Nohup and wait command usage


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Nohup and wait command usage
# 1  
Old 11-14-2018
Nohup and wait command usage

Code:
while read list
do

nohup ./process.sh $list &

process_id=$!

wait $process_id

done < sample.lst

command1..

command2..


//Am calling a shell script within and firing the multiple processes concurrently.

// I have to wait until all the above processes are finished and have to execute command1

//How do i assign the individual processes into a process id and wait

If i try the above code, will the processes gets triggered concurrently? or it wait for first process to finish and then start second process?

My requirement is to trigger all the processes to run in the background concurrently and wait for all them to finish. and then execute next commands in the main script.
# 2  
Old 11-14-2018
There are some problems with your script.
1. the wait inside the loop waits on each child process in turn, not for all child processes running at once. Put a single wait outside the loop.

2. If your list is long the whole process can have problems when you run large numbers of child processes. The ulimit command is your friend. I would give you a how-to but I need to know the UNIX system and the shell you use for the project.

Please include system and shell information in your reply.

Last edited by jim mcnamara; 11-14-2018 at 09:40 AM..
# 3  
Old 11-14-2018
Code:
while read list
do

nohup ./process.sh $list &

process_id=$!

echo "$prcoess_id" >> process_id.lst

done < sample.lst

while read process_id
do
wait $process_id
done <process_id.lst

command1

command 2


will this work?
# 4  
Old 11-14-2018
In post#1, you'll start a list's process in background, and then immediately sit there waiting for it to finish before starting the next one. So - serial execution, nothing in parallel. Try dropping the individual waits, and place a generic one after the loop.

Last edited by RudiC; 11-14-2018 at 09:53 AM..
# 5  
Old 11-14-2018
Which still leaves the process count limit problem.
# 6  
Old 11-14-2018
I will only have these processes anywhere between 5 - 10 in total. Do i still need to bother about count limit? Forget about limit for now. Is my code a effective one?
# 7  
Old 11-14-2018
You don't need the process id's for anything.
Code:
while read list
do
        nohup ./process.sh $list &
done < sample.lst

wait

command1

command 2

This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Wait time shows high CPU usage

Hi, I can't seem to make sense of this. My wait time is showing really high but vmstat's and topas are showing normal usage. ps aux USER PID %CPU %MEM SZ RSS TTY STAT STIME TIME COMMAND root 9961810 5680.7 0.0 448 384 - A Dec 16 6703072:12 wait ... (2 Replies)
Discussion started by: techy1
2 Replies

2. Shell Programming and Scripting

In Shell Script Does Second Command Wait For First Command To Complete

Hi All, I have a question related to Shell scripting. In my shell script, I have following two commands in sequence: sed 's/^/grep "^120" /g' $ORIGCHARGEDAMTLIST|sed "s;$;| cut -f$FIELD_NO1 -d '|' | awk '{ sum+=\$1} END {printf (\"%0.2f\\\n\", sum/100)}' >$TEMPFILE mv $TEMPFILE $ORIGFILE... (3 Replies)
Discussion started by: angshuman
3 Replies

3. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

4. Shell Programming and Scripting

Usage of NOHUP - How to keep the child process running even if I close the Server connection

Hi. ! When I use the 'NOHUP' along with the '&', the process will be running in the background. Even when I attempt to close (Meaning 'EXIT') the session (say PUTTY in this case), it wont exit unless the process is completed. But, say when I forcefully terminate the session (SHUT DOWN the... (2 Replies)
Discussion started by: WinBarani
2 Replies

5. Shell Programming and Scripting

Wait command help

Hi, Is there any way to know the child process status as and when it finished. If i write like below nohup sh a1.sh & ### has sleep 20 ;echo a1.sh nohup sh a2.sh & ### has sleep 10 ;echo a2.sh nohup sh a3.sh & ### has sleep 5 ;echo a3.sh wait This will wait till a1.sh ,a2.sh a3.sh... (0 Replies)
Discussion started by: patrickk
0 Replies

6. Shell Programming and Scripting

wait command

Hi all, I have never used the wait command before and want to know how it works. I basically need to run four sqlplus sessions in parallel as background processes and i am spooling the results obtained from the database into files.I need to wait for all the processes to finish and then make... (2 Replies)
Discussion started by: vinoo128
2 Replies

7. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

8. 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

9. UNIX for Dummies Questions & Answers

nohup usage..

Hi, I want to run the below 3 sql files parallely..I know adding a "&" at the end of the command will make it run in background.But each sql file will take a considerable time to execute so i want to apply "nohup" to this execution. Help me how to use " nohup " to these... echo... (2 Replies)
Discussion started by: charan81
2 Replies

10. Shell Programming and Scripting

Wait Command

Does anyone have an example of a korn shell scripts kicking of multiple background processes and then using the wait command to get the return code from those processes? I want to write a program that kicks off multiple Oracle procedures and then wait for the return code before I procede.... (1 Reply)
Discussion started by: lesstjm
1 Replies
Login or Register to Ask a Question