Linux C: upon receiving a signal, is it possible to know the PID of the sender?
问题 Suppose my C program handles SIGUSR1. When it receives the signal, is it possible to know who sent it? I.e,. to get the pid of that process? 回答1: Yes, if you use the sigaction call to set up your signal handler instead of signal . Doing so will let you set up a signal handler that takes three parameters: An int , for the signal number (just like signal ) A siginfo_t * , which is a structure containing all sorts of information about the source of the signal, including the pid of the sender if