孤儿进程:因为父进程先退出而导致一个子进程被init进程收养的进程为孤儿进程。
因此,可以通过创建孤儿进程,改变native进程的父进程,达到防止系统清理。
关键代码实现:
#include
#include
#include
int main()
{
pid_t child_pid;
child_pid=fork();
if(child_pid<0)
{
perror("fork error");
exit(EXIT_FAILURE);
}
if(child_pid==0)//子进程处理 事务
{
while(1)
{
printf("hello world\n");
sleep(1);
}
return 0;
}else
{
printf("father bye byte\n");
exit(EXIT_SUCCESS);
}
}

本文链接:https://it72.com/5996.htm