Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _XOPEN_SOURCE 700
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/msg.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/msg.h>
- #include <time.h>
- #include <wait.h>
- struct bufor{
- int mtype;
- int mvalue;
- };
- int main(){
- char tab[30];
- int pdesk[2];
- int i;
- key_t klucz;
- int msgID;
- struct tm *czas_tm;
- time_t czas_t;
- int l_sek;
- //Tworzenie klucza i kolejki komunikatow
- klucz=ftok(".",'A');
- if(klucz==-1)
- {
- printf("Blad klucza\n");
- exit(1);
- }
- msgID=msgget(klucz,IPC_CREAT|IPC_EXCL|0666);
- if(msgID==-1)
- {
- printf("Blad msgID\n");
- exit(1);
- }
- struct bufor komunikat;
- if(fork()==0)
- {
- pipe(pdesk);
- if(fork()==0)
- {
- //czas
- /*close(1);
- dup(pdesk[1]);
- close(pdesk[0]);
- close(pdesk[1]);*/
- fprintf(stderr,"podaj date: YYYY-MM-DD HH:MM:SS\n");
- fgets(tab, 20, stdin);
- fprintf(stderr,"---Podaleś date: %s\n",tab);
- fprintf(stderr,"test\n"); //to pokazuje
- if(strptime(tab,"%Y-%m-%e %H:%M:%S",czas_tm) == NULL)
- {
- printf("ERROR");
- exit(1);
- }
- printf("test\n");//tego już nie pokazuje
- czas_t = mktime(czas_tm);
- printf("test\n");//tego też nie pokazuje
- printf("%d",(int)czas_t);
- }
- else{
- //sek
- close(0);
- dup(pdesk[0]);
- close(pdesk[0]);
- close(pdesk[1]);
- scanf("%d",&l_sek);
- printf("po pipe=%d\n",l_sek);
- komunikat.mtype=1;
- komunikat.mvalue=l_sek;
- if(msgsnd(msgID,&komunikat,sizeof(komunikat.mvalue),0) == -1)
- {
- printf("blad wyslania kom. (p)\n");
- exit(1);
- }
- fprintf(stderr,"wyslano kom");
- }
- }
- else
- {
- //main
- wait(NULL);
- wait(NULL);
- execlp("./biela2","biela2",NULL);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement