fork - Print the values generated by each child process in c -


I have cut number of process n number of times for children, after forking, at some point, Random numbers are required to be generated and therefore I write a statement to do this. But before I go ahead, I have to produce every child in random numbers on the terminal. When I write printf (), I get only one output which I believe is the parent-generated random numbers. Can anyone help me to keep all RPNNumber in place of my address to print?

Also, since every child will execute them when they call them to print their rnd_number values, I am surprised that they were not printed on the terminal. If I am getting some concepts, then I request someone to help me.

You wait in Dad to eliminate every child. If it ends before their children, children will not print anything.

Regarding the print, do not forget that this function buffers the data, beware of using '\ n' to force the fluff of the printf. To know which child gets random, you want to print his PIN using the getpid () function.

  pid = fork (); Switch (case) {case '0': // son srand (time (faucet)); // Despite a process, a child feels better than doing this procedure in the father RR = rand ()% X; // keep your random here printf ("% d to% d received from \ n", r, getpid ()); Return r; // Submit case for Father Rand price -1: // error perror ("fork"); Exit (1); Default: // parent entity status; Wait (& amp; status); Printf ("% d to% d pass", WEXITSTATUS (status), pid); }   

The code for the same process, but you got this idea. You have to use the same fashion for your multiprase program.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -