Process, where each process generates a random integer


 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Process, where each process generates a random integer
# 1  
Old 02-06-2012
Java 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.
# 2  
Old 02-06-2012
Is this homework?

What have you tried?
# 3  
Old 02-06-2012
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.
Code:
{
  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


Last edited by zxmaus; 02-06-2012 at 10:18 PM..
# 4  
Old 02-06-2012
Please post your homework in the homework forum following the homework rules.
# 5  
Old 02-06-2012
Parallel Processing - Creating Process, where each process generates a random integer

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.

2. Relevant commands, code, scripts, algorithms:

rand() fork()

3. The attempts at a solution (include all code and scripts):
int Myproc(int id) // couldn't figure out this part.
4. 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).

Last edited by zxmaus; 02-06-2012 at 10:19 PM.. Reason: moved and merged posts, removed duplicate info
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to get exact tomcat process I am running ignoring other java process

Team, I have multiple batchjobs running in VM, if I do ps -ef |grep java or tomcat I am getting multiple process list. How do I get my exact tomcat process running and that is unique? via shell script? (4 Replies)
Discussion started by: Ghanshyam Ratho
4 Replies

2. Shell Programming and Scripting

Monitoring processes in parallel and process log file after process exits

I am writing a script to kick off a process to gather logs on multiple nodes in parallel using "&". These processes create individual log files. Which I would like to filter and convert in CSV format after they are complete. I am facing following issues: 1. Monitor all Processes parallelly.... (5 Replies)
Discussion started by: shunya
5 Replies

3. Hardware

CUDA GPU terminates process at random instances

I am trying to start troubleshooting an error on a virtual server that uses the ubuntu 14.04 OS. Basically what happens (seeming random) is that the GPU stops processing and terminates. What Imean by seeming random is that for 3 runs there is no error then on run 4 the error appears. It has... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (1 Reply)
Discussion started by: naveeng
1 Replies

5. BSD

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (0 Replies)
Discussion started by: naveeng
0 Replies

6. Programming

Generating Random Number in Child Process using Fork

Hello All, I am stuck up in a program where the rand functions ends up giving all the same integers. Tried sleep, but the numbers turned out to be same... Can anyone help me out how to fix this issue ? I have called the srand once in the program, but I feel like when I call fork the child process... (5 Replies)
Discussion started by: manisum
5 Replies

7. Shell Programming and Scripting

script to monitor the process system when a process from user takes longer than 15 min run.

get email notification from from system when a process from XXXX user takes longer than 15 min run.Let me know the time estimation for the same. hi ,any one please tell me , how to write a script to get email notification from system when a process from as mentioned above a xxxx user takes... (1 Reply)
Discussion started by: kirankrishna3
1 Replies

8. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

9. Shell Programming and Scripting

shell script to auto process ten random files and generate logs

Hello member's I'm learning to script in the ksh environment on a Solaris Box. I have 10 files in a directory that I need to pass, as input to a batch job one by one. lets say, the files are named as follows: abcd.txt ; efgh.bat ; wxyz.temp etc. (random filenames with varied extensions ).... (1 Reply)
Discussion started by: novice82
1 Replies

10. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies
Login or Register to Ask a Question