Thread: How to prevent exiting from running program

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    6

    Question How to prevent exiting from running program

    Hi all...

    I am developing a C programme for database management, and I need to make it unclosable unless the quit button is clicked. So I shall be realy thankful if anybody could help me out and tell me how to do it.
    I want to isable everything right from Ctrl+z to suspend to Ctrl+c for exit and Ctrl+Alt+Delete if possibal at all.

    Thanks in advance....

  2. #2
    still a n00b Jaguar's Avatar
    Join Date
    Jun 2002
    Posts
    187
    >> and I need to make it unclosable unless the quit button is clicked
    for GUI, don't know

    following for console
    Code:
    #include <signal.h>
    
    signal(SIGINT,SIG_IGN); /* disable ctrl-C */
    signal(SIGQUIT,SIG_IGN); /* disable ctrl-\ */
    signal(SIGTSTP,SIG_IGN); /* disable ctrl-Z */
    slackware 10.0; kernel 2.6.7
    gcc 3.4.0; glibc 2.3.2; vim editor
    migrating to freebsd 5.4

  3. #3
    Registered User
    Join Date
    Jan 2004
    Posts
    6

    Re: How to prevent exiting from running program

    Originally posted by scorpio_IITR
    I want to isable everything right from Ctrl+z to suspend to Ctrl+c for exit and Ctrl+Alt+Delete if possibal at all.
    all you can do is catch a bunch of 'allowed' signals:

    stopping (sort of ):
    SIGINT (Ctrl-C)
    SIGABRT(Ctrl-\)
    SIGTERM
    SIGHUP

    pausing:
    SIGSTP (Ctrl-Z)

    you can't catch SIGKILL (kill -9) or SIGSTOP, as they're handled by the kernel; Ctrl+Alt+Del is a different story: in console mode, init snatches it, in X usually the desktop manager does. either way, you probably won't see it (and well you shouldn't - you can't handle the reset button either )

  4. #4
    still a n00b Jaguar's Avatar
    Join Date
    Jun 2002
    Posts
    187

    Re: Re: How to prevent exiting from running program

    >> SIGABRT(Ctrl-\)
    ?*?*? SIGQUIT

    >> SIGSTP (Ctrl-Z)
    SIGTSTP
    slackware 10.0; kernel 2.6.7
    gcc 3.4.0; glibc 2.3.2; vim editor
    migrating to freebsd 5.4

  5. #5
    Registered User
    Join Date
    Jan 2004
    Posts
    6

    Re: Re: Re: How to prevent exiting from running program

    Originally posted by Jaguar
    >> SIGABRT(Ctrl-\)
    ?*?*? SIGQUIT

    >> SIGSTP (Ctrl-Z)
    SIGTSTP
    yeah, SIGTSTP (sorry for the typo).

    however, Ctrl-\ may send either the Posix "Quit" (SIGQUIT) or the Ansi "Abort" (SIGABRT) - it's terminal-dependent.

  6. #6
    Registered User
    Join Date
    Dec 2003
    Posts
    6
    thanks for help buddies....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Exiting the program.
    By Taka in forum C Programming
    Replies: 6
    Last Post: 10-14-2007, 09:24 AM
  2. How to tell when internal program is done running
    By PJYelton in forum Windows Programming
    Replies: 5
    Last Post: 03-21-2005, 10:09 PM
  3. Replies: 0
    Last Post: 04-27-2003, 02:04 AM
  4. exiting program
    By spike232 in forum C# Programming
    Replies: 4
    Last Post: 05-25-2002, 08:18 PM
  5. prevent exiting
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-12-2001, 02:57 PM