标签:
fork.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> void main(){ int pid; pid = fork(); printf("pid is %d\n", pid); exit(0); }
vfork.c
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> void main(){ int pid; pid = vfork(); printf("pid is %d\n", pid); exit(0); }
wait.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <wait.h> void main(){ int pid; pid = fork(); if(pid > 0){ wait(NULL); printf("pid is %d\n", pid); }else{ printf("pid is %d\n", pid); } exit(0); }
excel.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <wait.h> void main(){ int pid; pid = fork(); if(pid > 0){ wait(NULL); printf("pid is %d\n", pid); }else{ execl("/bin/ls", "ls", NULL); printf("pid is %d\n", pid); //不会被执行 } exit(0); }
标签:
原文地址:http://www.cnblogs.com/d442130165/p/5223552.html