soulrpg

xd

Nov 27th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <signal.h>
  4. #include <unistd.h>
  5. #include <sys/ipc.h>
  6. #include <sys/shm.h>
  7. #include <string.h>
  8. void obsluga(int sig)
  9. {
  10. printf("sygnał w procesie %d\n", getpid());
  11. }
  12. int main()
  13. {
  14. int id;
  15. char *ptr;
  16. int pid;
  17. signal(SIGHUP, obsluga);
  18. id = shmget(0x111, 1024, 0600 | IPC_CREAT);
  19. if (id==-1)
  20. {
  21. perror("shmget");
  22. exit(1);
  23. }
  24. ptr = (char*)shmat(id, NULL, 0);
  25. if ((pid=fork())==0)
  26. {
  27. int ppid = getppid();
  28. sleep(1);
  29. while(1)
  30. {
  31. strcpy(ptr, "xxxxxx");
  32. sleep(1);
  33. kill(ppid, 1);
  34. pause();
  35. strcpy(ptr, "oooooo");
  36. sleep(1);
  37. kill(ppid, 1);
  38. pause();
  39. }
  40. }
  41. else
  42. {
  43. while(1)
  44. {
  45. pause();
  46. printf("%s\n", ptr);
  47. sleep(1);
  48. kill(pid, 1);
  49. }
  50. }
  51. }
Add Comment
Please, Sign In to add comment