Process, where each process generates a random integer

Hello all, I am writing a program where user enters an integer and the program creates that number of processes. Each child process generates a random integer. When a child process calls a procedure say Myprocedure it should terminate where as the parent process wait for the child to terminate.

Is this homework?

What have you tried?

yeah sort of a HW, but more of a prac program. so far I have tried this - should the fork() be in a separate loop, like first create all processes and then print random integer and at last terminate.
int Myproc(int id) // couldn't figure out this part.

{
  if(!id)
  return wait(id);

  else
  exit(1);
}

int main()
{
	pid_t p_id;
        int num;
        printf("Enter Number of processes : ");
        scanf ("%d",num);
for (int i = 0; i < num - 1; i++)
	
{
        p_id = fork();

	if(p_id == -1){
		printf("Unable to create process/child");
		return(-1);}

	if(!p_id)
		//printf("Parent Control Starts here.");
	else
	// Child Control
        // Generate random number.
        printf (" Child ID = %d --- %d", p_id, (rand() % 100 + 1) ); // random integer between 1 to 100
}// end for

}//end main

Please post your homework in the homework forum following the homework rules.

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

Hello all, I am writing a program where user enters an integer and the program creates that number of processes. Each child process generates a random integer. When a child process calls a procedure say Myprocedure it should terminate where as the parent process wait for the child to terminate.

  1. Relevant commands, code, scripts, algorithms:

rand() fork()

  1. The attempts at a solution (include all code and scripts):
    int Myproc(int id) // couldn't figure out this part.
  2. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    NU-FAST, Pakistan, Ms. Mehreen, CS314, www[dot].nu[dot].edu

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).