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 <string.h>
- #include <signal.h>
- #include <stdlib.h>
- #include <sys/ioctl.h>
- #include <fcntl.h>
- void sig_handler(int sig)
- {
- write(1, "SIGTTIN received\n", 17);
- exit(0);
- }
- int main()
- {
- pid_t child_pid;
- char msg[256];
- child_pid = fork();
- memset(msg, 0, 256);
- if (child_pid == 0)
- {
- setpgid(0, 0); /* Create new process group */
- signal(SIGTTIN, sig_handler);
- sleep(2);
- read(0, msg, 255);
- write(1, "\nPunks not dead!\n", 17);
- }
- else if (child_pid > 0)
- {
- sleep(1);
- ioctl(0, TIOCSPGRP, &child_pid);
- signal(SIGTTIN, sig_handler);
- read(0, msg, 255);
- wait(&child_pid);
- write(1, "Child execution finished\n", 25);
- }
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement