Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char** argv) {
- pid_t pid_potomka;
- char *komunikat;
- int powtorzen;
- pid_t mojPid;
- pid_t pidRodzica;
- printf("Na razie dziala jeden proces\n");
- pid_potomka = fork();
- switch (pid_potomka) {
- case -1:
- printf("rozwidlenie procesu nie powiodlo sie\n");
- exit(1);
- case 0:
- mojPid = getpid();
- pidRodzica = getppid();
- komunikat = "Jestem potomkiem";
- powtorzen = 5;
- break;
- default:
- komunikat = "Jestem rodzicem";
- mojPid = getpid();
- pidRodzica = getppid();
- powtorzen = 5;
- break;
- }
- for (; powtorzen > 0; powtorzen--) {
- puts(komunikat);
- printf("Moj: %d\n", mojPid);
- printf("Rodzica: %d\n", pidRodzica);
- sleep(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement