我的信號處理程序是這樣的:用C停止守護進程
volatile sig_atomic_t loop = 1;
void handle()
{
loop = 0;
}
而且,我有一個守護進程是這樣的:
void _start_()
{
...
sa.sa_handler = handle;
sigaction(SIGINT, &sa, NULL);
while(loop)
{
//add a line to a file
}
...
}
我想stop
守護進程,從像另一個功能:
void _stop_()
{
raise(SIGINT);
}
我的想法是,如果莫名其妙的loop
值爲0,那麼while
將被評估爲false,並且守護進程退出。 我打算使用這兩個功能,如:
_start_(); //daemon starts
//computation
_stop_() //daemon stops writing to the file. exits
我該如何做到這一點?問題是我無法從_stop_()
停止守護進程。
感謝
您是否試圖用調試器查看程序? – 2012-04-24 03:06:17
請您詳細說明一下嗎? – Sayan 2012-04-24 03:31:05