Wait status


 
Thread Tools Search this Thread
Top Forums Programming Wait status
# 1  
Old 06-04-2012
Wait status

hi all!

In my C++ program I have a parent process which forks 5 children processes.The processes do a job and then they have to do some sort of sleeping(not terminate) until the parent wakes them up again.There might be 1,2,5 or even 0 processes awake at any moment.The thing is that in the parent process there's the

Code:
int status;
wait(&status);

for every process.But this refers to the termination of each process.How can a process do a job and then "sleep" instead of terminate.I guess with some sort of a signal but I have absolutely no idea how this can be achieved.
Any ideas?
# 2  
Old 06-04-2012
The most obvious way would be a pipe... The child reads from the read end of the pipe, but when there's nothing to be read, that will cause it to wait. The parent writes when it wants to wake the child up.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 06-05-2012
Quote:
Originally Posted by Corona688
The most obvious way would be a pipe... The child reads from the read end of the pipe, but when there's nothing to be read, that will cause it to wait. The parent writes when it wants to wake the child up.
So in that case the parent doesn't have to use the wait-status at all right?
(I forgot to mention that when the parent wants all of its children to terminate it sends a certain signal..)
# 4  
Old 06-05-2012
wait() waits for children to die. If they're not supposed to die, don't wait() at all.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 06-05-2012
I see.So if I understood correctly the parent has a pipe for each of its children and depending on what child it wants to wake up writes to that pipe right?
But how does the parent know which children are "sleeping" in order to write to their pipe and not to the pipe of a child which is running?
# 6  
Old 06-05-2012
Does it matter? It writes the message and whoever gets it, gets it and deals with it when they read it.

To put it another way, what are you actually trying to do here by waking up processes?
# 7  
Old 06-05-2012
Quote:
Originally Posted by Corona688
Does it matter? It writes the message and whoever gets it, gets it and deals with it when they read it.

To put it another way, what are you actually trying to do here by waking up processes?
The parent process sends a string message to the children in order to do some things.When a child is finished waits for the next string message.Only one child can deal with each message but there's a chance that more than one children deal with messages at the same time.That happens because while a child is dealing with a msg, the parent might want to send another msg which has to be received from a child that does nothing at the time,so in that case 2 children are working at the same time.My question was how the parent knows which of its children are "waiting" and which are "working",in order to send the msg to one of the sleeping ones.If I use pipes,do I have to use one for each child?Also how do I make sure that no more than one children gets the msg string?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to see the status of all the ftp put & get files logs and curent ftp transfer status ?

How to see the status of all the ftp put & get files logs and curent ftp transfer status if any active ftp running in the background ? (2 Replies)
Discussion started by: i4ismail
2 Replies

2. Programming

How to track table status delete/update/insert status in DB2 V10 z/os?

Dear Team I am using DB2 v10 z/os database . Need expert guidance to figure out best way to track table activities ( Ex Delete, Insert,Update ) Scenario We have a table which is critical and many developer/testing team access on daily basis . We had instance where some deleted... (1 Reply)
Discussion started by: Perlbaby
1 Replies

3. Shell Programming and Scripting

How to get script to wait until status is true before continuing?

I'm extremely new to shell scripting so I apologize for the crudeness of my descriptions. I am editing a script that will write files (e.g. Job0_A.com, Job1_A.com, etc.) and then run them through a program called gaussian (computational chemistry program). The script will then take the output files... (10 Replies)
Discussion started by: butson
10 Replies

4. Shell Programming and Scripting

calling a shell script in background and wait using "wait" in while loop

Hi, I am facing a strange issue, when i call a script from my while loop in background it doesnt go in background, despite the wait i put below the whil loop it goes forward even before the process put in background is completed. cat abc.txt | while read -u4 line do #if line contains #... (2 Replies)
Discussion started by: mihirvora16
2 Replies

5. Red Hat

WAIT

Can someone explain what is the status says WAIT on performance monitoring command.. (2 Replies)
Discussion started by: suresh_krish
2 Replies

6. Shell Programming and Scripting

wait command - cat it wait for not-chile process?

Did not use 'wait' yet. How I understand by now the wait works only for child processes, started background. Is there any other way to watch completion of any, not related process (at least, a process, owned by the same user?) I need to start a background process, witch will be waiting... (2 Replies)
Discussion started by: alex_5161
2 Replies

7. Shell Programming and Scripting

Need to execute 2 scripts, wait, execute 2 more wait, till end of file

:cool: I need to execute a shell script to do the following: cat a file run two back ground processes using the first two values from the file wait till those background processes finish run two more background processes using the next two values from the file wait till those background... (1 Reply)
Discussion started by: halo98
1 Replies

8. Red Hat

Installing RedHat 8.0 onto Dell PowerEdge SC1425 - hdc: status error: status = 0x58

I have successfully installed RedHat 8.0 onto a Dell PowerEdge SC1425 today. This server has two SATA hard drives, and an IDE DVD-ROM drive. Using the following kernel parameters, i successfully installed across both hard drives from CD: ide0=0x1f0,0x3f6,14 vga=791 resolution=1024x768 expert... (5 Replies)
Discussion started by: fishsponge
5 Replies

9. Shell Programming and Scripting

check the status and send an email with status

Hi, We have a text file which has the following data. ISA~00~ ~00~ ~ZZ~VISTN ~ZZ~U1CAD ~051227~183 7~U~00200~000011258~0~P~< GS~FA~EE05J~U1CAD~051227~1831~000011258~X~002002 ST~997~0001 AK1~SH~247 AK2~856~2470001 AK5~A AK2~856~2470002 AK5~A... (3 Replies)
Discussion started by: isingh786
3 Replies

10. UNIX for Dummies Questions & Answers

Couldn't open status file /var/samba/STATUS.LCK

I believe i have most of samba configured right but i get this error each time time try to run it. I was given suggestion that i touch the file, i did, but i still cannot rid myself of this error. Any suggestions (2 Replies)
Discussion started by: macdonto
2 Replies
Login or Register to Ask a Question