Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <unistd.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <string.h>
- void obsluga(int sig)
- {
- printf("sygnał w procesie %d\n", getpid());
- }
- int main()
- {
- int id;
- char *ptr;
- int pid;
- signal(SIGHUP, obsluga);
- id = shmget(0x111, 1024, 0600 | IPC_CREAT);
- if (id==-1)
- {
- perror("shmget");
- exit(1);
- }
- ptr = (char*)shmat(id, NULL, 0);
- if ((pid=fork())==0)
- {
- int ppid = getppid();
- sleep(1);
- while(1)
- {
- strcpy(ptr, "xxxxxx");
- sleep(1);
- kill(ppid, 1);
- pause();
- strcpy(ptr, "oooooo");
- sleep(1);
- kill(ppid, 1);
- pause();
- }
- }
- else
- {
- while(1)
- {
- pause();
- printf("%s\n", ptr);
- sleep(1);
- kill(pid, 1);
- }
- }
- }
Add Comment
Please, Sign In to add comment