相关疑难解决方法(0)

关于在Unix中实现系统功能的困惑

system来自APUE的Unix 功能的实现:

图8.22 system无需信号处理的功能

#include    <sys/wait.h>
#include    <errno.h>
#include    <unistd.h>

int
system(const char *cmdstring)   /* version without signal handling */
{
    pid_t   pid;
    int     status;

    if (cmdstring == NULL)
        return(1);      /* always a command processor with UNIX */

    if ((pid = fork()) < 0) {
        status = -1;    /* probably out of processes */
    } else if (pid == 0) {              /* child */
        execl("/bin/sh", "sh", "-c", cmdstring, (char *)0);
        _exit(127);     /* execl error */
    } …
Run Code Online (Sandbox Code Playgroud)

c unix

1
推荐指数
1
解决办法
53
查看次数

标签 统计

c ×1

unix ×1