📄 testsleep.cpp
字号:
#include <stdio.h>#include <stdlib.h>#include <time.h>#include <string.h>#include <fcntl.h>#include <termios.h>#include <unistd.h>#include <sys/io.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/wait.h>#include <sys/file.h>#include <pthread.h>#include <semaphore.h>#include <sys/ioctl.h>
/*********************** main ***********************************/int main(void){ int j=0; pid_t pid; j++; printf("======== Time=%ld,PID=%d,Main process j=%d =====\n",time(NULL),getpid(),j);//======================= First Create process...Ready ============================== //Process 1 pid=fork(); if(pid==0){ printf("...... Time=%ld,PID=%d,Process 1# is Running j=%d ......\n",time(NULL),getpid(),j); sleep(5); printf("------- Time=%ld,PID=%d,Process 1# Exit j=%d-------\n",time(NULL),getpid(),j); exit(1); } else if(pid==-1){ printf("...... fork() process 1# error......\n"); return -1; } //process 2 pid=fork(); if (pid==0){ printf("------- Time=%ld,PID=%d,Process 2# Exit j=%d-------\n",time(NULL),getpid(),j); sleep(15); exit(1); }else if (pid==-1){ printf("...... forking process 2# error ......\n"); return -1; } //process 3 pid=fork(); if (pid==0){ printf("------- Time=%ld,PID=%d,Process 3# Exit j=%d-------\n",time(NULL),getpid(),j); sleep(25); exit(1); }else if (pid==-1){ printf("...... forking process 3# error ......\n"); return -1; } waitpid(pid,NULL,0); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -