Причем тут system? В заголовке даже подсказка есть - execlp.
Код | #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h>
int compile(const char* infile, const char* outfile) { int pid; pid = fork();
if (pid < 0) { perror("fork"); return -1; } else if (pid > 0) { printf("Started process %d\n", pid); } else if (pid == 0) { if (execlp("gcc", "gcc", "-o", outfile, infile, (char*)0) < 0) { perror("exec"); return -1; } }
return pid; }
void waitchild(int pid) { int status;
waitpid(pid, &status, 1); printf("Process %d exit status %d\n", pid, status); }
int main() { int pid1;
if ((pid1 = compile("hello1.c", "h1")) < 0) { return -1; }
int pid2;
if ((pid2 = compile("hello2.c", "h2")) < 0) { return -1; }
waitchild(pid1); waitchild(pid2);
return 0; } |
|