Question: 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

 In Linux, threads are implemented as lightweight processes. (1) what is

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

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!