Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I replace fork() with clone() system call and compile it successfully. #include #include #include #include #include #include int main(int argc , char *argv[])

How do I replace fork() with clone() system call and compile it successfully.

#include #include #include #include #include #include int main(int argc , char *argv[]) { if (argc!=2){ printf("Invalid argument. Exiting. "); exit(0); }

//converting string argument to integer int n = atoi(argv[1]); if (n<=0){ printf("Non-positive argument is invalid. Exiting. "); exit(0); } pid_t pid = fork(); if (pid<0){ printf("Child couldn't be created. Exiting. "); exit(0); } else if (pid==0) { //This is child Process while (n!=1) { printf("%d ", n); if(n%2==0) { //n is even n = n/2; }

else { //n is odd n = 3*n+1; } }

printf("1 ");

exit(0); } else { //This is parent process //Wait for child process to complete wait(NULL); } }

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_2

Step: 3

blur-text-image_3

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

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions