fork download
/*    main program illustrating the UNIX fork() system call. 
Compile using cc -o main main.c
*/
#include <stdio.h>
main() {
int fork(), childpid, value;

childpid = fork(); /* create a new process */

if(childpid == -1) {
	perror("can’t fork. Help!!");
	exit(-1);
	} 

 else if(childpid == 0) { /* child process */
	printf("child: my_process_id= %d,parent_process_id=%d\n", getpid(), getppid());
	/* Transform the child process to another program called Hello */
	/* Note the many variations of exec that exist! */
	printf("Parent: About to run hello program \n");
	if((value = execl("hello", "hello",0)) == -1) {
		perror("couldn’t do exec!!");
		exit(-1);
		}
	} 

 else { /* parent process */
	printf("Parent: my_process_id=%d,my_child’s_process_id=%d",getpid(), childpid);
	exit(0);
	}  /* end if */
} 
Success #stdin #stdout #stderr 0s 5432KB
stdin
Standard input is empty
stdout
Parent: my_process_id=15578,my_child’s_process_id=15599child: my_process_id= 15599,parent_process_id=1
Parent: About to run hello program 
stderr
couldn’t do exec!!: No such file or directory