Consider the following code segment pidt pid pid fork if pi

Consider the following code segment:

pid_t pid;

pid = fork();

if (pid == 0 { /*Child process*/
   fork();
   thread_create(...);
}
for();

a. How many unique processes are created?

b. How many unique threads are created?

Solution

fork() creates a new child process.

on calling the fork() the program will be split into two processes, one is the main which called the fork() method and the other is child process which is created on calling of fork() method.

so there are tow unique processes created.

When a process starts it\'s execution, it starts with a default thread. Every process has atleast one thread of control. the thread_create() creats a new thread for that particular process with a unique thread id.

main process has one thread.

child process has one thread on start of execution.

on calling thread_create() it creates one more thread.

so there are three unqiue threads created.

Consider the following code segment: pid_t pid; pid = fork(); if (pid == 0 { /*Child process*/ fork(); thread_create(...); } for(); a. How many unique processes

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site