Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/wait.h>
  4. #include <string.h>
  5. #include <signal.h>
  6. #include <stdlib.h>
  7. #include <sys/ioctl.h>
  8. #include <fcntl.h>
  9.  
  10. void    sig_handler(int sig)
  11. {
  12.     write(1, "SIGTTIN received\n", 17);
  13.     exit(0);
  14. }
  15.  
  16. int     main()
  17. {
  18.     pid_t   child_pid;
  19.     char    msg[256];
  20.  
  21.     child_pid = fork();
  22.     memset(msg, 0, 256);
  23.     if (child_pid == 0)
  24.     {
  25.         setpgid(0, 0); /* Create new process group */
  26.         signal(SIGTTIN, sig_handler);
  27.         sleep(2);
  28.         read(0, msg, 255);
  29.         write(1, "\nPunks not dead!\n", 17);
  30.     }
  31.     else if (child_pid > 0)
  32.     {
  33.         sleep(1);
  34.         ioctl(0, TIOCSPGRP, &child_pid);
  35.         signal(SIGTTIN, sig_handler);
  36.         read(0, msg, 255);
  37.         wait(&child_pid);
  38.         write(1, "Child execution finished\n", 25);
  39.     }
  40.     return (0);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement