6linux多进程解释.ppt

本章内容 进程 vs 线程 Linux创建进程函数:fork Linux获得进程标识符函数:getpid,getppid Linux进程执行函数:exec函数族 Linux终止进程函数:exit Linux等待进程函数:wait waitpid #include sys/types.h #include stdio.h #include unistd.h #include stdlib.h int main(void) { pid_t pid; pid=fork(); if( pid==0){ printf(child\n); sleep(3); exit(0); }else if(pid0){ waitpid(pid, NULL, 0); printf(parent\n); exit(0); }else{ perror(“fork fail”); exit(-1);} } #include sys/types.h #include stdio.h #include unistd.h #include stdlib.h int main(void) { pid_t pid,wpid; wpid=waitpid(-1, NULL, WNOHANG); printf(first-pid:%d\n,wpid); if( (pid=f

文档评论(0)

1亿VIP精品文档

相关文档