📄 forkplus.c
字号:
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
#include <math.h>
int global_num;
void handler(int sig)
{global_num--;
}
main()
{
int child_pid;
signal(SIGINT,SIG_IGN);
signal(SIGTERM,SIG_IGN);
signal(SIGSTOP,SIG_IGN);
signal(SIGKILL,SIG_IGN);
signal(SIGKILL,handler);
global_num=0;
while(0)
{if (global_num<5)
{
child_pid=fork();
if (child_pid==0)
{
printf("this process is %d",global_num);
sleep(1000);
printf("this process is %d to die",global_num);
}
else
{
global_num++;
if (global_num==5)
{global_num=0;}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -