In Linux, threads are implemented as lightweight processes. (1) Explain the clone system call in detail, including the function and arguments (2) What is the difference between a process create by the following code and a process created by system call fork() (3) Analyse the following code, please compose the code in the blan (4) what is the command-line arguments to make the calling process and the child process run in the same memory space

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

In Linux, threads are implemented as lightweight processes.

(1) Explain the clone system call in detail, including the function and arguments

(2) What is the difference between a process create by the following code and a process created by system call fork()

(3) Analyse the following code, please compose the code in the blan
(4) what is the command-line arguments to make the calling process and the child process run in the same memory space

#define tid() syscall_NR_gettid)
#define pid() syscall(SYS_getpid)
#define SSIZE 1024*1024
int func1( 1 )
{
printf("\nin child sees buf = %s", (char *)buf1);
sprintf(bufl, "hello from child tid=%ld, pid=%ld\n", tid(), pid());
printf(" change the buffer to: %s\n", (char *)buf1);
return 0;
}
Transcribed Image Text:#define tid() syscall_NR_gettid) #define pid() syscall(SYS_getpid) #define SSIZE 1024*1024 int func1( 1 ) { printf("\nin child sees buf = %s", (char *)buf1); sprintf(bufl, "hello from child tid=%ld, pid=%ld\n", tid(), pid()); printf(" change the buffer to: %s\n", (char *)buf1); return 0; }
int main( 2 )
{
char* st1 = malloc(SSIZE);
if (!st1) {
perror("malloc");exit(1);
}
unsigned long flags = 0;
if((arge > 1) && (!stremp(argv[1], "thread")))
flags |= CLONE_VM;
char buf[100];
sprintf(buf, "hello from parent pid=%ld\n", pid());
printf("in parent process before clone\n buf=%s", buf);
if (clone(_3 func1, st1 + SSIZE, flags|SIGCHLD , buf) = -1) {
perror("clone");exit(1);
}
int status2;
if (_4 waitpid(-1,&status2,0) == -1) {
perror("wait"); free(stack2);exit(1);
}
printf("in parent process: child exited with status %d.\n buf = %s \n", status2, buf);
free(stack);
return 0;
}
Transcribed Image Text:int main( 2 ) { char* st1 = malloc(SSIZE); if (!st1) { perror("malloc");exit(1); } unsigned long flags = 0; if((arge > 1) && (!stremp(argv[1], "thread"))) flags |= CLONE_VM; char buf[100]; sprintf(buf, "hello from parent pid=%ld\n", pid()); printf("in parent process before clone\n buf=%s", buf); if (clone(_3 func1, st1 + SSIZE, flags|SIGCHLD , buf) = -1) { perror("clone");exit(1); } int status2; if (_4 waitpid(-1,&status2,0) == -1) { perror("wait"); free(stack2);exit(1); } printf("in parent process: child exited with status %d.\n buf = %s \n", status2, buf); free(stack); return 0; }
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY