Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <time.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- struct tm *
- psbody(int fd)
- {
- time_t t;
- read(fd, &t, sizeof(t));
- close(fd);
- struct tm *stm = localtime(&t);
- return stm;
- }
- int
- main(void)
- {
- int fds[2];
- pipe(fds);
- time_t t = time(NULL);
- write(fds[1], &t, sizeof(t));
- write(fds[1], &t, sizeof(t));
- write(fds[1], &t, sizeof(t));
- pid_t ps;
- if (!(ps = fork())) {
- close(fds[1]);
- pid_t pg;
- if (!(pg = fork())) {
- pid_t pgg;
- if (!(pgg = fork())) {
- struct tm *stmgg = psbody(fds[0]);
- printf("S:%02d\n", stmgg->tm_sec);
- _exit(0);
- }
- waitpid(pgg, NULL, 0);
- struct tm *stmg = psbody(fds[0]);
- printf("M:%02d\n", stmg->tm_min);
- _exit(0);
- }
- waitpid(pg, NULL, 0);
- struct tm *stms = psbody(fds[0]);
- printf("H:%02d\n", stms->tm_hour);
- _exit(0);
- }
- waitpid(ps, NULL, 0);
- close(fds[0]);
- close(fds[1]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement