I need to send a signal to a process and when the process receives this signal it does some things, how is this best achieved in C?
Sending signals to foreground processesPressing Ctrl+C sends an Interrupt signal (SIGINT) to the process and the process terminates.
The way to send a signal to a process is kill(pid, signal); However, you should be aware that signals are not a robust means of inter-process communication except for parent-to-direct-child messages due to inherent race conditions.
signal() sets the disposition of the signal signum to handler, which is either SIG_IGN, SIG_DFL, or the address of a programmer- defined function (a "signal handler"). If the signal signum is delivered to the process, then one of the following happens: * If the disposition is set to SIG_IGN, then the signal is ignored.
The way to send a signal to a process is kill(pid, signal);
However, you should be aware that signals are not a robust means of inter-process communication except for parent-to-direct-child messages due to inherent race conditions. Pipes, files, directories, named semaphores, sockets, shared memory, etc. all provide greatly superior approaches to inter-process communication.
If you happen to be on one of the Unix variants, the following man pages will help:
man 2 kill
man 2 signal
man 2 sigvec
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With