Sponsored Content
Top Forums Shell Programming and Scripting Keep up constant number of parallel processes Post 302770055 by Corona688 on Thursday 14th of February 2013 10:09:41 AM
Old 02-14-2013
What is your system? What is your shell?

On BASH, you can wait for one specific process, so you can do this:

Code:
maxproc=5
set --
while [[ condition ]]
do
        process &

        set -- $* $!
        [ "$#" -gt maxproc ] && wait "$1" && shift
done

wait

Drawback is it just waits for the oldest process, not necessarily the first finished.
 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run processes in parallel?

In a korn shell script, how can I run several processes in parallel at the same time? For example, I have 3 processes say p1, p2, p3 if I call them as p1.ksh p2.ksh p3.ksh they will run after one process finishes. But I want to run them in parallel and want to display "Process p1... (3 Replies)
Discussion started by: sbasak
3 Replies

2. Shell Programming and Scripting

Trim not constant number of symbols ?

Hello, I need to trim zeros from left side: #echo $var1 00023456 But number of zeros is not constant. How do I do that ? thanks Vilius (4 Replies)
Discussion started by: vilius
4 Replies

3. Shell Programming and Scripting

Retention of Variable Value when a script is called by different processes in parallel- Linux 2.6.9

Hi, I have a generic FTP script which will be called by 28 different processes in parallel (through a GUI tool) may or may not be at the exact moment (there could be a delay of about a minute or so). ./FTP.ksh 1 (1 through 28) This script after importing file from remote m/c... (1 Reply)
Discussion started by: dips_ag
1 Replies

4. Shell Programming and Scripting

Parallel processes to INC- and DEC-rement shared counter

QUESTION: How do I run processes in parallel, so that the counter (in counter.txt) would vary in value (instead of just "0" and "1")? That is, how to not sequentially run inc.sh and dec.sh? The shared counter (a single number starting as 0) is in a file counter.txt. counter.sh is (supposed to... (2 Replies)
Discussion started by: courteous
2 Replies

5. Shell Programming and Scripting

Deleting all the parallel processes launched when the main script receives a ctrl+c

Hi, I have a shell script that creates 2 parallel processes. When I press ctrl+c, i want the parallel process to get killed as well. #!/bin/bash cmd1="script1.py" cmd2="script2.py" ${cmd1} & pid1=$! echo ${pid1} ${cmd2} & pid2=$! (7 Replies)
Discussion started by: sana.usha
7 Replies

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

7. Shell Programming and Scripting

(bash) Script Processes in Parallel

Hello all, I tried to parralise my treatments but after a while 'ps -ef' display all child process <defunct> (zombie) Parent bash script to process all files (>100000) in directory: for filename in /Data/*.txt; do ./child_pprocess.sh $filename & done exit(0)I understand that the... (1 Reply)
Discussion started by: namnetes
1 Replies
STARTPAR(8)                                                   System Manager's Manual                                                  STARTPAR(8)

NAME
startpar - start runlevel scripts in parallel SYNOPSIS
startpar [-p par] [-i iorate] [-t timeout] [-T global_timeout] [-a arg] prg1 prg2 ... startpar [-p par] [-i iorate] [-t timeout] [-T global_timeout] -M [ boot|start|stop] DESCRIPTION
startpar is used to run multiple run-level scripts in parallel. The degree of parallelism on one CPU can be set with the -p option, the default is full parallelism. An argument to all of the scripts can be provided with the -a option. Processes blocked by pending I/O will cause new process creation to be weighted by the iorate factor 800. To change this factor the option -i can be used to specify another value. The amount weight=(nblockedxiorate)/1000 will be subtracted from the total number of processes which could be started, where nblocked is the number of processes currently blocked by pending I/O. The output of each script is buffered and written when the script exits, so output lines of different scripts won't mix. You can modify this behaviour by setting a timeout. The timeout set with the -t option is used as buffer timeout. If the output buffer of a script is not empty and the last output was timeout seconds ago, startpar will flush the buffer. The -T option timeout works more globally. If no output is printed for more than global_timeout seconds, startpar will flush the buffer of the script with the oldest output. Afterwards it will only print output of this script until it is finished. The -M option switches startpar into a make(1) like behaviour. This option takes three different arguments: boot, start, and stop for reading .depend.boot or .depend.start or .depend.stop respectively in the directory /etc/init.d/. By scanning the boot and runlevel direc- tories in /etc/init.d/ it then executes the appropriate scripts in parallel. FILES
/etc/init.d/.depend.boot /etc/init.d/.depend.start /etc/init.d/.depend.stop SEE ALSO
init(8) insserv(8). COPYRIGHT
2003,2004 SuSE Linux AG, Nuernberg, Germany. 2007 SuSE LINUX Products GmbH, Nuernberg, Germany. AUTHOR
Michael Schroeder <mls@suse.de> Takashi Iwai <tiwai@suse.de> Werner Fink <werner@suse.de> Jun 2003 STARTPAR(8)
All times are GMT -4. The time now is 10:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy