Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that: 1) Asks from the user an integer number N (N>10) 2) Create

ID: 3671017 • Letter: W

Question

Write a program that:

1) Asks from the user an integer number N (N>10)

2) Creates N processes that:

a) Each process prints its own PID

b) Each process prints the current time (Tip: check the C date and time funcations)

3) The parent process should print its own ID

4) Run the program 5 times and keep the output. Is it different in some cases?

Explain why this happens

5) Are the PIDs of the processes the same each time you execute the program ?

6) What is the maximum limit to the number of processes possible in a Unix system ? Verify with your program

Explanation / Answer

//same program different code
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>

int main()
{
int pid[5];
int i;
  
for (i = 0; i < 5; i++)
{ int p = fork();
if (p < 0)
{
printf(" Error ");
return 1;
}
if (p == 0)
{
printf(" Hello I am the child process, pid: %d", getpid());
return 0;
}
}

printf(" Hello I am the parent process , pid: %d", getpid());

return 0;
}


-----------------------------------

cat /proc/sys/kernel/pid_max
32768

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote