Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.16 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #include <unistd.h>
  4.  
  5. #include <sys/wait.h>
  6.  
  7. #include <time.h>
  8.  
  9. int
  10. main(int argc, char
  11.   const * argv[]) {
  12.   int fd[2];
  13.   struct tm * tt;
  14.   pipe(fd);
  15.   if (!fork()) {
  16.     if (!fork()) {
  17.       if (!fork()) {
  18.         close(fd[0]);
  19.         time_t cur_time = time(NULL);
  20.         write(fd[1], & cur_time, sizeof(cur_time));
  21.         write(fd[1], & cur_time, sizeof(cur_time));
  22.         write(fd[1], & cur_time, sizeof(cur_time));
  23.         close(fd[1]);
  24.         return 0;
  25.       }
  26.       close(fd[1]);
  27.       wait(NULL);
  28.       time_t cur_time;
  29.       read(fd[0], & cur_time, sizeof(cur_time));
  30.       tt = localtime( & cur_time);
  31.       printf("D:%02d\n", tt - > tm_mday);
  32.       close(fd[0]);
  33.       return 0;
  34.     }
  35.     close(fd[1]);
  36.     wait(NULL);
  37.     time_t cur_time;
  38.     read(fd[0], & cur_time, sizeof(cur_time));
  39.     tt = localtime( & cur_time);
  40.     printf("M:%02d\n", tt - > tm_mon + 1);
  41.     close(fd[0]);
  42.     return 0;
  43.   }
  44.   close(fd[1]);
  45.   wait(NULL);
  46.   time_t cur_time;
  47.   read(fd[0], & cur_time, sizeof(cur_time));
  48.   tt = localtime( & cur_time);
  49.   printf("Y:%04d\n", tt - > tm_year + 1900);
  50.   close(fd[0]);
  51.   return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement