Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

child2replacement

#include <stdio.h>

#include <string.h>

#include <unistd.h>



int main()

{

	int PID;

	int childnum;



	for(childnum=1; childnum<=3; childnum++)

	{

		PID=fork();



		if (PID>0)

		{

			printf("Parent, my pid is %d: Spawned child #%d whose pid is %d\n", getpid(), childnum, PID);

		}



		else

		{

			printf("I am child #%d, my pid is %d; my parent's pid is %d\n", childnum, getpid(), getppid());



			if (childnum==2)

				execv("child2replacement",NULL);



			childnum=10;

		}	

	}
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.