码迷,mamicode.com
首页 > 系统相关 > 详细

proc -x cshell fork()

时间:2015-05-16 17:52:16      阅读:132      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!