@RamilH/

OS Fork counting

C

No description

fork
loading
Files
  • main.c

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.22040574550858394","path":"main.c","file":{"path":"main.c","content":{"asEncoding":{"base64":"I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzeXMvdHlwZXMuaD4KI2luY2x1ZGUgPHVuaXN0ZC5oPgoKaW50IHZhbHVlID0gNTsKCmludCBtYWluKHZvaWQpIAp7CiAgcGlkX3QgcGlkOwoKICBwaWQgPSBmb3JrKCk7CgoKICBpZiAocGlkID09IDApIHsKICAgIHdhaXQoTlVMTCk7CiAgICB2YWx1ZSArPSAxNTsKICAgIHByaW50ZigiXG5DSElMRDogdmFsdWUgPSAlZCIsIHZhbHVlKTsKICAgIHJldHVybiAwOwogIH0KCiAgZWxzZSBpZiAocGlkID4gMCkKICB7CiAgICB3YWl0KE5VTEwpOwogICAgcHJpbnRmKCJcblBBUkVOVDogdmFsdWUgPSAlZCIsIHZhbHVlKTsgLyogTElORSBBICovIAogICAgcmV0dXJuIDA7CiAgfQp9"},"asBuffer":null},"loaded":true}}
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
26
27
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int value = 5;

int main(void) 
{
  pid_t pid;

  pid = fork();


  if (pid == 0) {
    wait(NULL);
    value += 15;
    printf("\nCHILD: value = %d", value);
    return 0;
  }

  else if (pid > 0)
  {
    wait(NULL);
    printf("\nPARENT: value = %d", value); /* LINE A */ 
    return 0;
  }
}