File: test09.c

package info (click to toggle)
box64 0.3.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,880 kB
  • sloc: ansic: 373,273; python: 2,845; asm: 1,201; makefile: 267; sh: 112; cpp: 45
file content (21 lines) | stat: -rw-r--r-- 335 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h> 
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h> 
  
void forkexample() 
{ 
    int x = 1; 
  
    if (fork() == 0) 
        printf("Child has x = %d\n", ++x); 
    else {
        wait(NULL);
        printf("Parent has x = %d\n", --x); 
    }
} 
int main() 
{ 
    forkexample(); 
    return 0; 
}