首页 > 系统服务 > 详细

proc -x cshell fork()

时间:2015-05-16 17:51:05      阅读:191      评论:0      收藏:0      [点我收藏+]
 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] == \n)
14         buf[strlen(buf)-1] = 0;
15 if (( pid = fork()) < 0 )
16     printf("fork error\n");
17 else if (pid == 0){
18     execlp(buf,buf,(char *)0);
19     printf("could not execute : %s\n",buf);
20     exit(127);
21     }
22 if((pid = waitpid(pid,&status,0))<0)
23     printf("waitpid error\n");
24 }
25 }

 

proc -x cshell fork()

原文:http://www.cnblogs.com/pencil-zh/p/4508016.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!