user1762571
user1762571

Reputation: 1949

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)?

Upvotes: 3

Views: 1389

Answers (1)

Duck
Duck

Reputation: 27542

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().

Upvotes: 3

Related Questions