How to send a signal from one program to another?

I use message queue as ipc between two programs. Now I want to send data from one program to another using a message queue, and then inform it through a SIGINT signal.

I do not know how to send a signal from one program to another. Can anyone pls provide some sample code if they have a solution.

+6
linux signals
source share
4 answers
#include <sys/types.h> #include <signal.h> int kill(pid_t pid, int sig); 
+11
source share

You can send a signal to linux using the kill system call, just check this link to document the call and the kill kill example. you can also see how -2 man kills. and it is not practical to use SIGINT to use SIGUSR1 or SIGUSR2

+5
source share

Note that using the sigqueue () system call, you can pass an extra piece of data along with your signal. Here is a short quote from "man 2 sigqueue":

The value argument is used to indicate an accompanying data element (either an integer or a pointer value) to be sent with a signal, and has the following type:

  union sigval { int sival_int; void *sival_ptr; }; 

This is a very convenient way to transfer a small bit of information between two processes. I agree with the user above - use SIGUSR1 or SIGUSR2 and a good signal, and you can transfer whatever you want.

You can also pass a pointer to an object in shared memory via sival_ptr and pass a larger object this way.

+1
source share
 system("kill -2 `pidof <app_name_here>` "); 
-4
source share

All Articles