proc -x cshell fork()

 1 #include <stdlib.h>
 2 #include <stdio.h>
 3 #include <unistd.h>
 4 #include <string.h>
 5 #define MAXLINE 10
 6 int main(void)
 7 {
 8 char buf[MAXLINE];
 9 pid_t pid;
10 int status;
11 printf("%%");
12 while(fgets(buf,MAXLINE,stdin)!=NULL){
13     if(buf[strlen(buf)-1] == '
')
14         buf[strlen(buf)-1] = 0;
15 if (( pid = fork()) < 0 )
16     printf("fork error
");
17 else if (pid == 0){
18     execlp(buf,buf,(char *)0);
19     printf("could not execute : %s
",buf);
20     exit(127);
21     }
22 if((pid = waitpid(pid,&status,0))<0)
23     printf("waitpid error
");
24 }
25 }
原文地址:https://www.cnblogs.com/pencil-zh/p/4508016.html