Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <ncurses.h>
  2. #include<stdlib.h>
  3. #include<stdio.h>
  4. #include <ctime>
  5. #include <string>
  6. #include <unistd.h>
  7. #include <sys/wait.h>
  8. #include <sys/types.h>
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. initscr();
  14. start_color();
  15. time_t now;
  16. pid_t pid = fork();
  17. switch(pid){
  18. case -1:
  19. {
  20. perror("fork"); /* произошла ошибка */
  21. exit(1); /*выход из родительского процесса*/
  22. }
  23. case 0:
  24. {
  25. clear();
  26. time(&now);
  27. char str[26];
  28. ctime_r(&now,str);
  29. init_pair(1, COLOR_RED, COLOR_BLACK);
  30. attron(COLOR_PAIR(1));
  31. printw("\n\n CHILDW :");
  32. mvprintw(10,30,"%s",str);
  33. refresh();
  34. getch();
  35. attroff(COLOR_PAIR(1));
  36. exit(0);
  37. }
  38. default:
  39. {
  40. clear();
  41. wait(NULL);
  42. time(&now);
  43. char str[26];
  44. ctime_r(&now,str);
  45. init_pair(1, COLOR_RED, COLOR_BLACK);
  46. attron(COLOR_PAIR(1));
  47. printw("\n PARENT\n");
  48. mvprintw(20,30,"%s",str);
  49. refresh();
  50. getch();
  51.  
  52. }}
  53. endwin();
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement