Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger SIGUSR1 and SIGUSR2?

Tags:

c

signals

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?

like image 334
haunted85 Avatar asked May 29 '11 15:05

haunted85


People also ask

What is the difference between SIGUSR1 and SIGUSR2?

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.

What is signal SIGUSR1?

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.


2 Answers

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); 
like image 162
Oliver Charlesworth Avatar answered Sep 22 '22 05:09

Oliver Charlesworth


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 
like image 23
Евгений Кашинский Avatar answered Sep 20 '22 05:09

Евгений Кашинский