I'm getting acquainted with signals in C. I can't figure out what kind of signals SIGUSR1
and SIGUSR2
are and how can I trigger them. Can anyone please explain it to me?
Other than the actual signal number, there's no difference between them. There are two signals so that you can have two different signals to communicate between processes. Maybe SIGUSR1 means re-read the first configuration file and SIGUSR2 means re-read the second configuration file.
The SIGUSR1 and SIGUSR2 signals are set aside for you to use any way you want. They're useful for simple interprocess communication, if you write a signal handler for them in the program that receives the signal. There is an example showing the use of SIGUSR1 and SIGUSR2 in Signaling Another Process.
They are user-defined signals, so they aren't triggered by any particular action. You can explicitly send them programmatically:
#include <signal.h> kill(pid, SIGUSR1);
where pid
is the process id of the receiving process. At the receiving end, you can register a signal handler for them:
#include <signal.h> void my_handler(int signum) { if (signum == SIGUSR1) { printf("Received SIGUSR1!\n"); } } signal(SIGUSR1, my_handler);
terminal 1
dd if=/dev/sda of=debian.img
terminal 2
killall -SIGUSR1 dd
go back to terminal 1
34292201+0 records in 34292200+0 records out 17557606400 bytes (18 GB) copied, 1034.7 s, 17.0 MB/s
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