Question: Copy clone_mpmProcess.c to clone_mpmThread.c and modify the latter so that it spawns a thread (some call it a lightweight process) instead of a process. Your

Copy clone_mpmProcess.c to clone_mpmThread.c and modify the latter so that it spawns a thread (some call it a lightweight process) instead of a process. Your output should be (except for pids): > clone_mpmThread

This is process(thread) 11504. x+y=1 > This is process(thread) 11505. x+y=8

Code for clone_mpmProcess.c is:

#include  #include  #include  #include  #include  #define STACK 8192 int child_func(){ int x = 0, y = 0; printf (" This is process (thread) %d. ", getpid()); y = 1; printf("x + y = %d ", x + y); } int main ( void ) { void *stack = malloc(STACK); if(!stack){ printf ("malloc failed "); return 1; } int x = 0, y = 0; pid_t pid, fpid; if(clone(&child_func, (char*) stack + STACK, 0, NULL) < 0){ printf ("clone failed "); return (1); } pid = getpid(); sleep(1); printf (" This is process(thread) %d. ", pid); x = 7; printf("x + y = %d ", x + y); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!