Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions