前面讲了守护进程, 并且自己也写了一个简单的守护进程, 我们来继续看看更简单的方式:

#include <stdio.h>
#include <unistd.h>

int main()
{
	daemon(1, 1);
	int x = 0;
	while(1)
	{
		printf("hello %d\n", x++);
		sleep(1);
	}

	return 0;
}
      运行一下./a.out, 可以发现, 跟直接nohup ./a.out &一样, 进程不会受到Ctrl C和关闭Shell的影响, 爽爽哒。




本文转载:CSDN博客