Write the C Program in which the parent process will create the child process using the fork() system call. Following functionality be performed in the parent and child process. • In parent process you have to display your name, roll no and academic program at
University of Gujrat. • In the child process you have to execute the binary executable "pwd" by using execlp
system call to display the current working directory.

Respuesta :

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.

Writting in C++:

#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

Ver imagen lhmarianateixeira
ACCESS MORE
EDU ACCESS