1

Can we create a program that can't be stopped by operating system? For ex. overriding all the signals like CTRL+C, CTRL+Z etc. so whenever operating system sends kill signal to the program it will simply ignore it.

displayName
  • 13,888
  • 8
  • 60
  • 75
  • Probably you are looking for this http://stackoverflow.com/questions/10046916/is-it-possible-to-ignore-all-signals , try the accepted answer – asio_guy Sep 12 '15 at 06:54
  • Somehow Microsoft finds a way to right such programs. – user3344003 Sep 13 '15 at 01:18
  • 1
    SIGSTOP and SIGKILL cannot be ignored or treated. You have to cope with that, or you'll have to rewrite some code in the kernel (and break it, making it non posix conformant) – Luis Colorado Sep 13 '15 at 10:04

1 Answers1

3

You can ignore most signals via the signal system call as follows:

signal(SIGINT, SIG_IGN);

Here, we set the signal handler for SIGINT (which gets raised when you press CTRL+C) to be SIG_IGN, which is a special flag stating that that signal is to be ignored.

However, from the man page for signal(2):

The signals SIGKILL and SIGSTOP cannot be caught or ignored.

So while you can ignore a SIGINT (i.e. CTRL+C), you can't ignore SIGSTOP (CTRL+Z) or SIGKILL.

dbush
  • 205,898
  • 23
  • 218
  • 273