#include <unistd.h>
void _exit(int status);
#include <stdlib.h>
void _Exit(int status);
status参数:是进程退出时的状态信息,父进程在回收子进程资源的时候可以获取到
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>int main() {printf("hello\n");printf("world");// exit(0);_exit(0);return 0;
}
exit()函数退出时会刷新I/O缓冲,而_exit()函数退出时不会刷新I/O缓冲
#include <sys/types.h>
#include <unistd.h>
#include<stdio.h>
int main() {//创建子进程pid_t pid = fork();//判断是父进程还是子进程if(pid > 0) {printf("I am parent process, pid : %d, ppid : %d\n", getpid(), getppid());} else if(pid == 0) {sleep(1);printf("I am child process, pid : %d, ppid : %d\n", getpid(), getppid());}for(int i = 0; i < 5; i++) {printf("i : %d\n", i);}return 0;
}
#include <sys/types.h>
#include <unistd.h>
#include<stdio.h>
int main() {//创建子进程pid_t pid = fork();//判断是父进程还是子进程if(pid > 0) {while(1) {printf("I am parent process, pid : %d, ppid : %d\n", getpid(), getppid());sleep(1);}} else if(pid == 0) {printf("I am child process, pid : %d, ppid : %d\n", getpid(), getppid());}for(int i = 0; i < 5; i++) {printf("i : %d\n", i);}return 0;
}