The Open Source Swiss Army Knife

/code/c/unix_c/fork/
/code/c/unix_c/fork/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /code   /c   /unix_c   /fork 
Permalink: simplefork.c
Title: add
article options : please login   |  raw source view  

/* http://vip.cs.utsa.edu/usp/  dr.robbins utsa computer science  "unix systems programming" */
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>

int main(void) {
   int x;
   pid_t pid;
   x = 0;
   printf("before fork: I am process %ld and my x is %d\n", (long)getpid(), x);
   pid = fork();

   x = 1;
	if (pid > 0) { 
		printf("after fork: I am process %ld and my x is %d\n", (long)getpid(), x);
		wait(pid);
	}
	if (pid == 0) { 
		printf("I am process %ld and my x is %d\n", (long)getpid(), x);
		sleep(10);
	}
   return 0;
}

Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top