进程退出

子进程退出,有些资源需要父进程去释放
cpp
/*
#include <stdlib.h>
void exit(int status);
#include <unistd.h>
void _exit(int status);
status参数: 进程退出的一个状态信息。父进程回收资源的时候可以获取
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int main() {
printf("hello\n");
printf("world");
//exit(0);
_exit(0);
return 0;
}
第一个printf带上了\n会自动做刷新IO缓冲区的操作,第二个没有\n就一直在缓冲区里面
调用标准C库的exit函数时,它会再做一次刷IO新缓冲区的操作,输出world
但是Linux的_exit函数就不会做这个操作,最后只输出hello
孤儿进程
父进程执行完毕,只有子进程在执行,然后子进程的ppid就是1 也就是init
僵尸进程

wait()和waitpid()是释放子进程的函数