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
Get step-by-step solutions from verified subject matter experts
