Witam. Właśnie piszę prosty program związany z procesami. Niestety, wynikły dwa problemy:
- Program wypisuje teskt dla drugiego i trzeciego procesu w sposób losowy
Proces macierzysty:
UID=28009 GID=10000 PID=8381 PPID=5742 PGID=8381
Proces potomny 1:
UID=28009 GID=10000 PID=8382 PPID=8381 PGID=8381
Proces potomny 2:
Proces potomny 3:
UID=28009 GID=10000 PID=8383 PPID=1 PGID=8381
UID=28009 GID=10000 PID=8384 PPID=1 PGID=8381
Proces macierzysty:
UID=28009 GID=10000 PID=8286 PPID=5742 PGID=8286
Proces potomny 1:
UID=28009 GID=10000 PID=8287 PPID=8286 PGID=8286
Proces potomny 3:
Proces potomny 2:
UID=28009 GID=10000 PID=8289 PPID=1 PGID=8286
UID=28009 GID=10000 PID=8288 PPID=1 PGID=8286
- Nie mogę użyć funkcji getpgid(), gdyż dostaję komunikat: > implicit declaration of function ‘getpgid’
Proszę o pomoc w odnalezieniu błędu.
Kod:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main()
{
int i=0;
printf("Proces macierzysty:\n");
printf("UID=%d GID=%d PID=%d PPID=%d PGID=%d\n", getuid(), getgid(), getpid(), getppid(), getpgrp());
for(i=1; i<=3; i++)
{
switch(fork())
{
case -1:
perror("Cos poszlo nie tak...\n");
return 1;
break;
case 0:
printf("Proces potomny %d:\n", i);
printf("UID=%d GID=%d PID=%d PPID=%d PGID=%d\n", getuid(), getgid(), getpid(), getppid(), getpgrp());
_exit(0);
break;
}
}
/*getchar();*/
return 0;
}