summaryrefslogtreecommitdiff
path: root/lab05/procs.c
blob: cf1a9ff7508a9b464f6e4bb1fe2c57ba15fd3f33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>

int global;

int main()
{
	if (fork()) {          /* only the 1st parent enters here */
		fork();        /* ...to fork() a 2nd child...     */
	}

	/* All 3 processes (parent and children) run the following */

	global = getpid();     /* set to a process-specific value */
	sleep(1);
	printf("PID is %d, global = %d\n", getpid(), global);
}