Tag: exec

子进程之间的UNIX管道

我正在尝试编写一个程序,它将生成任意数量的子进程并在它们之间进行管道传输,类似于命令行管道。 在我的情况下,我正在尝试“ls -l | more”并将其输出到stdout,然后让父级继续执行更多命令。 我将以下代码作为最小示例: int main (int argc, const char * argv[]) { int fd[2]; pipe(fd); chdir(“/directory/with/lots/of/files”); // Create one child process for more int pid = fork(); if (pid == 0) { close(fd[1]); int ret = dup2(fd[0],0); if (ret < 0) perror("dup2"); char *argv[10]; argv[0] = "more"; argv[1] = NULL; execvp("more", argv); […]

在C中遇到fork(),pipe(),dup2()和exec()时遇到问题

这是我的代码: #include #include #include #include #include #define NUMPIPES 2 int main(int argc, char *argv[]) { char *bBuffer, *sPtr, *aPtr = NULL, *pipeComms[NUMPIPES], *cmdArgs[10]; int fdPipe[2], pCount, aCount, i, status, lPids[NUMPIPES]; pid_t pid; pipe(fdPipe); while(1) { bBuffer = readline(“Shell> “); if(!strcasecmp(bBuffer, “exit”)) { return 0; } sPtr = bBuffer; pCount = -1; do { aPtr = […]

沟通c程序和PHP

我想要一个显示输入值的网页(用PHP编写,因为它是我所知道的)。 我希望将该值传递给已经运行的ac程序。 我虽然使用套接字在两个进程之间进行通信,但我该如何设法做到这一点? 如何使用fsockopen连接到本地套接字。

如何使用正确的参数调用C中的execl()?

如果我输入一个shell,我有vlc(重现video的程序): / home / vlc“/ home / my movies /我想看的电影.mkv” 它打开了一个再现电影。 但是,当我运行以下程序时: #include int main(void) { execl(“/home/vlc”, “/home/my movies/the movie i want to see.mkv”,NULL); return 0; } vlc打开但不会重现任何内容。 我怎么解决这个问题? 我试过的事情: 我猜的 execl(“/home/vlc”, “/home/my movies/the movie i want to see.mkv”,NULL); 相当于在shell中输入: /home/vlc /home/my movies/the movie i want to see.mkv 这不起作用,所以我试过 execl(“/home/vlc”, “\”/home/my movies/the movie i want […]

如何使用C函数执行Shell内置命令?

我想通过像execv()这样的C语言函数执行Linux命令“pwd”。 问题是没有一个名为“pwd”的可执行文件,我无法执行“echo $ PWD”,因为echo也是一个没有可执行文件的内置命令。