Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/wait.h>
  4.  
  5. int main(int argc, char *argv[]) {
  6.     pid_t pid;
  7.     int fd[2];
  8.     char buffer[4096];
  9.     errno = 0;
  10.  
  11.     if (argc < 2) {
  12.     printf("Usage ./log command \n");
  13.     return;
  14.     }
  15.  
  16.     printf("[LOG] Début du programme pid : %d \n", getpid());
  17.    
  18.     int err = pipe(fd);
  19.     if (err == -1) {
  20.     printf("Erreur lors de la création du pipe\n");
  21.     return -1;
  22.     }
  23.  
  24.     pid = fork();
  25.  
  26.     if (pid == 0) {
  27.     dup2(fd[1], STDOUT_FILENO);
  28.     close(fd[0]);
  29.     close(fd[1]);
  30.     int err = execlp(argv[1], argv[1], (char *) 0);
  31.     if (err == -1) {
  32.         printf("Erreur execlp argv[1] \n");
  33.         return -1;
  34.     }
  35.     }
  36.    
  37.     else if (pid > 0) {
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement