aboutsummaryrefslogtreecommitdiff
path: root/semestr-5/so/lista1/rozwiazania/ex2a.c
blob: 63b26dbc14c5d2efdc5d680aa15eec594cb87ed2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
  printf("[%d] Ex2, parent pid: %d\n", getpid(), getppid());

  int pid = fork();
  if (pid < 0) {
    printf("Fork error\n");
    exit(1);
  }
  if (pid == 0) {
    for (int i = 0; i < 10; i++) {
      printf("[%d] Child process, parent pid: %d\n", getpid(), getppid());
      sleep(1);
    }
  }
  else {
    printf("[%d] Sleeping for a second.\n", getpid());
    sleep(1);
    printf("[%d] Exit.\n", getpid());
    exit(0);
  }
}