Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Linux, threads are implemented as lightweight processes. (1) what is the difference between this lightweight process (thread) and the normal process in Linux? [4

image text in transcribed

In Linux, threads are implemented as lightweight processes. (1) what is the difference between this lightweight process (thread) and the normal process in Linux? [4 marks] (2) Refer to the code in Figure 2, please IDENTIFY and EXPLAIN the function of two process-related system call in detail, including all the arguments in the code. [12 marks] (3) What is the difference between a process create by the following code and a process created by system call fork(); [2 marks] (4) Refer to the code in Figure 2, what is the input command line argument in the shell to get the running output in Figure 3. [2 marks] [total 20 marks] int main(int argc, char** argv) { char* stack = malloc(STACK_SIZE); if (!stack) { perror("malloc"); exit(1); } unsigned long flags = 0; if((argc > 1) && (!strcmp(argv[1], "thread"))) flags |= CLONE VM; char buf[100]; sprintf(buf, "hello from parent pid=eld ", getpid()); printf("in parent process before clone buf=%s", buf); if (clone(funci, stack + STACK_SIZE, flags SIGCHLD, buf) == -1) { perror("clone"); exit(1); } int status; if (waitpid (-1,&status, ) == -1) { perror("wait"); free (stack); exit(1); } printf("in parent process: buf = 95 ", buf); free(stack); return; } Figure 2 in parent process before clone buf=hello from parent pid=83834 in child sees buf = hello from parent pid=83834 change the buffer to: hello from child pid=83835 in parent process: buf hello from child pid=83835

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

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

=+employee to take on the international assignment?

Answered: 1 week ago

Question

=+differences in home- and host-country costs of living?

Answered: 1 week ago