Chinaunix首页 | 论坛 | 博客
  • 博客访问: 539245
  • 博文数量: 493
  • 博客积分: 2891
  • 博客等级: 少校
  • 技术积分: 4960
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-17 17:11
文章分类

全部博文(493)

文章存档

2010年(493)

分类:

2010-03-27 11:24:03

#include
#include
#include
#include
int system(const char * cmdstring)
...{
    pid_t pid;
    int status;
    if(cmdstring == NULL)...{
        return (1);
    }
    if((pid = fork())<0)...{
        status = -1;
    }
    else if(pid == 0)...{  //子进中运行脚本命令
        execl("/bin/sh", "sh", "-c", cmdstring, (char *)0);
        -exit(127); //子进程正常执行则不会执行此语句
    }
    else...{  //父进程中等待子进程返回
            while(waitpid(pid, &status, 0) < 0)...{
                if(errno != EINTER)...{
                    status = -1;
                    break;
                }
            }
    }
    return status;
}
阅读(311) | 评论(0) | 转发(0) |
0

上一篇:返回值

下一篇:subshell

给主人留下些什么吧!~~