Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <time.h>
- int
- main(int argc, char
- const * argv[]) {
- int fd[2];
- struct tm * tt;
- pipe(fd);
- if (!fork()) {
- if (!fork()) {
- if (!fork()) {
- close(fd[0]);
- time_t cur_time = time(NULL);
- write(fd[1], & cur_time, sizeof(cur_time));
- write(fd[1], & cur_time, sizeof(cur_time));
- write(fd[1], & cur_time, sizeof(cur_time));
- close(fd[1]);
- return 0;
- }
- close(fd[1]);
- wait(NULL);
- time_t cur_time;
- read(fd[0], & cur_time, sizeof(cur_time));
- tt = localtime( & cur_time);
- printf("D:%02d\n", tt - > tm_mday);
- close(fd[0]);
- return 0;
- }
- close(fd[1]);
- wait(NULL);
- time_t cur_time;
- read(fd[0], & cur_time, sizeof(cur_time));
- tt = localtime( & cur_time);
- printf("M:%02d\n", tt - > tm_mon + 1);
- close(fd[0]);
- return 0;
- }
- close(fd[1]);
- wait(NULL);
- time_t cur_time;
- read(fd[0], & cur_time, sizeof(cur_time));
- tt = localtime( & cur_time);
- printf("Y:%04d\n", tt - > tm_year + 1900);
- close(fd[0]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement