Using knowledge in C++ it is possible to write code that uses the parent process will create the child process using the fork() system call.
#include<stdio.h>
#include <stdlib.h>
int cmpfunc(const void * a,
const void * b) { //function to return digit in asc order
return ( * (int * ) a - * (int * ) b);
}
int cmpfuncdesc(const void * a,
const void * b) { //function to return digit in desc order
return ( * (int * ) b - * (int * ) a);
}
int main() {
int n;
int result = 0;
int result1 = 0;
int rem;
int no;
int i = 1;
scanf("%d", & n);
if (fork() == 0) // Check for executing Child Process
{
while (result1 != n) {
result1 = result;
no = n;
int digits[4];
for (int i = 0; i < 3; i++) {
digits[i] = no % 10;
no = no / 10;
}
qsort(digits, 3, sizeof(int), cmpfunc); //Sorting in ascending order
int asc = 0;
for (int i = 0; i < 3; i++)
asc = asc * 10 + digits[i];
qsort(digits, 3, sizeof(int), cmpfuncdesc); //Sorting in Descending order
int desc = 0;
for (int i = 0; i < 3; i++)
desc = desc * 10 + digits[i];
result = abs(asc - desc);
printf("Child process %d: %dth %d\n", getppid(), i, result); //Printing the diff between max and min of number
n = result;
i++;
}
exit(0);
} else {
wait(NULL);
}
}
See more about C++ code at brainly.com/question/19705654
#SPJ1