请教!!!unix环境编程实例 双输出
#include "apue.h"#include "my_err.h"
#include <sys/wait.h>
int main()
{
char buf;
pid_t pid;
int status;
printf("%% ");
while(fgets(buf,MAXLINE,stdin) != NULL)
{
if(buf=='\n')
buf=0;
if(pid=fork()<0)
{err_sys("fork error");}
else if(pid==0){
execlp(buf,buf,(char *)0);
err_ret("couldnot execute:%s",buf);
exit(127);
}
if(pid=waitpid(pid,&status,0))
err_sys("waitpid error");
printf("%% ");
}
}
# ./a.out
% date
三3月 13 14:04:26 CST 2013
三3月 13 14:04:26 CST 2013
if(pid=fork()<0) //错误的根源正确的写法:if((pid=fork()) < 0) 首先非常感谢,但是每次运行完命令之后直接结束进程,退出?回复 2# txgc_wm
知道原因了 谢谢!回复 2# txgc_wm
页:
[1]