Answered step by step
Verified Expert Solution
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started