fork download
  1. int doPipe(int fd[], int endpoint, char * command)
  2. {
  3. int close;
  4.  
  5. if (endpoint == READ) {
  6. close = WRITE;
  7. } else {
  8. close = READ;
  9. }
  10.  
  11. switch(fork()) {
  12. case 0:
  13. test = close(fd[close]); assert (test==0);
  14. test = dup2(fd[endpoint], endpoint); assert (test==0);
  15. test = close(fd[endpoint]); assert (test==0);
  16. execl("/bin/bash", "/bin/bash", "-c", command, (char*)0);
  17. perror("Cannot execl %s", command);
  18. exit(1);
  19. case -1:
  20. perror("Cannot fork.");
  21. exit(1);
  22. }
  23. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘doPipe’:
prog.c:5: error: ‘READ’ undeclared (first use in this function)
prog.c:5: error: (Each undeclared identifier is reported only once
prog.c:5: error: for each function it appears in.)
prog.c:6: error: ‘WRITE’ undeclared (first use in this function)
prog.c:11: warning: implicit declaration of function ‘fork’
prog.c:13: error: ‘test’ undeclared (first use in this function)
prog.c:13: error: called object ‘close’ is not a function
prog.c:13: warning: implicit declaration of function ‘assert’
prog.c:14: warning: implicit declaration of function ‘dup2’
prog.c:15: error: called object ‘close’ is not a function
prog.c:16: warning: implicit declaration of function ‘execl’
prog.c:16: warning: incompatible implicit declaration of built-in function ‘execl’
prog.c:17: warning: implicit declaration of function ‘perror’
prog.c:18: warning: implicit declaration of function ‘exit’
prog.c:18: warning: incompatible implicit declaration of built-in function ‘exit’
stdout
Standard output is empty