Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #define _XOPEN_SOURCE 700
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/ipc.h>
  6. #include <sys/msg.h>
  7. #include <fcntl.h>
  8. #include <sys/stat.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <sys/msg.h>
  12. #include <time.h>
  13. #include <wait.h>
  14.  
  15. struct bufor{
  16. int mtype;
  17. int mvalue;
  18. };
  19.  
  20. int main(){
  21. char tab[30];
  22. int pdesk[2];
  23. int i;
  24. key_t klucz;
  25. int msgID;
  26. struct tm *czas_tm;
  27. time_t czas_t;
  28. int l_sek;
  29.  
  30. //Tworzenie klucza i kolejki komunikatow
  31.  
  32. klucz=ftok(".",'A');
  33. if(klucz==-1)
  34. {
  35. printf("Blad klucza\n");
  36. exit(1);
  37. }
  38.  
  39. msgID=msgget(klucz,IPC_CREAT|IPC_EXCL|0666);
  40. if(msgID==-1)
  41. {
  42. printf("Blad msgID\n");
  43. exit(1);
  44. }
  45.  
  46. struct bufor komunikat;
  47.  
  48. if(fork()==0)
  49. {
  50. pipe(pdesk);
  51. if(fork()==0)
  52. {
  53. //czas
  54.  
  55. /*close(1);
  56. dup(pdesk[1]);
  57. close(pdesk[0]);
  58. close(pdesk[1]);*/
  59.  
  60.  
  61. fprintf(stderr,"podaj date: YYYY-MM-DD HH:MM:SS\n");
  62. fgets(tab, 20, stdin);
  63. fprintf(stderr,"---Podaleś date: %s\n",tab);
  64.  
  65. fprintf(stderr,"test\n"); //to pokazuje
  66. if(strptime(tab,"%Y-%m-%e %H:%M:%S",czas_tm) == NULL)
  67. {
  68. printf("ERROR");
  69. exit(1);
  70. }
  71. printf("test\n");//tego już nie pokazuje
  72. czas_t = mktime(czas_tm);
  73. printf("test\n");//tego też nie pokazuje
  74. printf("%d",(int)czas_t);
  75. }
  76. else{
  77. //sek
  78. close(0);
  79. dup(pdesk[0]);
  80. close(pdesk[0]);
  81. close(pdesk[1]);
  82. scanf("%d",&l_sek);
  83. printf("po pipe=%d\n",l_sek);
  84.  
  85. komunikat.mtype=1;
  86. komunikat.mvalue=l_sek;
  87. if(msgsnd(msgID,&komunikat,sizeof(komunikat.mvalue),0) == -1)
  88. {
  89. printf("blad wyslania kom. (p)\n");
  90. exit(1);
  91. }
  92. fprintf(stderr,"wyslano kom");
  93. }
  94. }
  95. else
  96. {
  97. //main
  98. wait(NULL);
  99. wait(NULL);
  100. execlp("./biela2","biela2",NULL);
  101. }
  102. return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement