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