how to send signal from one program to another?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 22:18:49

问题


i am using message queue as an ipc between 2 programs. Now i want to send data from one program to another using message queue and then intimate it through a signal SIGINT.

I dont know how to send a signal from one program to another . Can anybody pls provide a sample code if they have the solution.


回答1:


#include <sys/types.h>
#include <signal.h>
int kill(pid_t pid, int sig);



回答2:


Signal in linux can be send using kill system call just check this link for documentation of kill system call and example. you can see man -2 kill also. and it's not advisable to use SIGINT use SIGUSR1 or SIGUSR2




回答3:


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

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

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

This is a very convenient way to pass a small bit of information between 2 processes. I agree with the user above -- use SIGUSR1 or SIGUSR2 and a good sigval, and you can pass whatever you'd like.

You could also pass a pointer to some object in shared memory via the sival_ptr, and pass a larger object that way.




回答4:


system("kill -2 `pidof <app_name_here>` ");


来源:https://stackoverflow.com/questions/637870/how-to-send-signal-from-one-program-to-another

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!