开发者

How to send and trap a signal sent to a PID, using C

开发者 https://www.devze.com 2023-03-03 15:09 出处:网络
Suppose, i know the process of my parent id 开发者_运维问答and would like to kill(my_parent_id, SIGTERM)

Suppose, i know the process of my parent id 开发者_运维问答and would like to

kill(my_parent_id, SIGTERM)

As a parent process, how can i catch this signal?


Register to catch the signal:

void termination_handler(int sig)
{
   /* do something */
}

struct sigaction handler;

handler.sa_handler = termination_handler;
sigemptyset (&handler.sa_mask);
handler.sa_flags = SA_RESTART;

sigaction(SIGTERM, &handler, NULL);

Here is a good example page.

You could use the old style, but it is not suggested:

void termination_handler()
{
    /* do something */
}

signal(SIGTERM, termination_handler);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号