简体   繁体   中英

Finding the process which sent signal in c

I have a child process which might receive sigterm signal from its parent or from somewhere else. I have to take appropriate action if the signal is from parent. How can i find if the received signal is from parent in c(linux)?

You set up your signal handler with sigaction using the SA_SIGINFO flag. Your handler will accept a parameter of siginfo_t . Within the siginfo_t struct is the field si_pid . This is the process id of the sending process. Match that against the child's ppid().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM