开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜