Bash: Regulating the number of processes a script can spawn


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Bash: Regulating the number of processes a script can spawn
# 8  
Old 05-08-2010
achenle,
your approach looks very promising, but I have following questions:

1. What does "set -bm" stand for?
2. How does the flow look like? There are two variants I can think of:
Let's assume every job will run for 5 minutes and let's forget about that SIGCHLD thing.
2.a It starts with line 20, the function startjob is called, "started=$(($started+1))" does *NOT* take effect, 1st job gets started, $count=1, line 20 calls the startjob function again ................................. $count=100 !! All 100 jobs are running at the same time.
2.b It starts with line 20, the function startjob is called, $started=1, 1st job gets started, $count=1, .... Script ends after 10 jobs, because $started=10.
3. IMHO that "wait" line is pretty unnecessary (pls. correct me if I'm wrong)

Is there an error in the way I think how it will work Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Is it possible to Divide a negative number in bash script

I am using a small script to divide some numbers in a given file and display the output in another file. I am getting the following error basename: invalid option -- '5' Try `basename --help' for more information. (standard_in) 1: syntax error The script is : #!/bin/bash for i in `cat... (4 Replies)
Discussion started by: kmnr877
4 Replies

3. Shell Programming and Scripting

SPAWN Multiple Processes in Unix

Hi, I have three files in my IN directory.Each file should be copied 25 times using for loop.Each file processing should run in parallel?How to spawn multiple processes in unix?Any help would be appreciated. Thanks, Liyakath (7 Replies)
Discussion started by: liyakathali
7 Replies

4. Shell Programming and Scripting

script for multi-threaded bash processes

hey everyone, I'm having some trouble breaking down some code. It's simple a control script that takes machines meant to be backed up from a list. Then according to that will run multi-threaded processes up until the specified thread limit. for example if there are 4 machines to be backed up,... (2 Replies)
Discussion started by: terrell
2 Replies

5. Shell Programming and Scripting

need to kill a number of processes with name "XYZ" at a time using shell script

Hi, when i grep for the process "XYZ" , there will be some good number of processes with that name, i want to kill all the these processes at a time using shell script? Any help needed for this action. Thanks Regards, Anil (6 Replies)
Discussion started by: anilmanepu
6 Replies

6. Shell Programming and Scripting

Printing the line number in bash script

Hi, I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened. Thanks, (6 Replies)
Discussion started by: suryaemlinux
6 Replies

7. Shell Programming and Scripting

Defining Dynamic Number of Variables in a Bash Script

Code: $ cat test.bash #!/bin/bash job=$1 steps=$2 num=$(echo "$@" | wc -w) Example Submission: $ ./test.bash BS01 3 1 2 3 What: (2 Replies)
Discussion started by: mkastin
2 Replies

8. Programming

Program to spawn multiple processes

I'm trying to make a program that will spawn multiple child processes then exit. I'm having trouble figuring out how to do this since after I fork, the child process begins running the program again (never ending). int main(void){ for(int i = 0; i < 3; i++){ fork(); }... (1 Reply)
Discussion started by: cagney58
1 Replies

9. Shell Programming and Scripting

shell script for getting pid of spawn processes from shell

Hi, I am new this forum. I request you peoples help in understanding and finding some solution to my problem. Here it goes: I need to perform this set of actions by writing a shell script. I need to read a config file for the bunch of processes to execute. I need to fecth the pid of... (4 Replies)
Discussion started by: sachin4sachi
4 Replies

10. Programming

Howto spawn multiple child processes and wait?

As far as I can tell, the bash wait command waits for a logical "AND" of all the child processes. Assuming I am coding in C: (1) What is the function I would use to create multiple bash child process running perl? (2) What is the function I would use to reinvent the bash wait command so I... (4 Replies)
Discussion started by: siegfried
4 Replies
Login or Register to Ask a Question
POSIX_SPAWNATTR_GETSCHEDPOLICY(3)			   BSD Library Functions Manual 			 POSIX_SPAWNATTR_GETSCHEDPOLICY(3)

NAME
posix_spawnattr_getschedpolicy, posix_spawnattr_setschedpolicy -- get and set the spawn-schedpolicy attribute of a spawn attributes object LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <spawn.h> int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *restrict attr, int *restrict schedpolicy); int posix_spawnattr_setschedpolicy(posix_spawnattr_t *attr, int schedpolicy); DESCRIPTION
The posix_spawnattr_getschedpolicy() function obtains the value of the spawn-schedpolicy attribute from the attributes object referenced by attr. The posix_spawnattr_setschedpolicy() function sets the spawn-schedpolicy attribute in an initialized attributes object referenced by attr. The spawn-schedpolicy attribute represents the scheduling policy to be assigned to the new process image in a spawn operation (if POSIX_SPAWN_SETSCHEDULER is set in the spawn-flags attribute). The default value of this attribute is unspecified. RETURN VALUES
The posix_spawnattr_getschedpolicy() and posix_spawnattr_setschedpolicy() functions return zero. SEE ALSO
posix_spawn(3), posix_spawnattr_destroy(3), posix_spawnattr_getschedparam(3), posix_spawnattr_init(3), posix_spawnattr_setschedparam(3), posix_spawnp(3) STANDARDS
The posix_spawnattr_getschedpolicy() and posix_spawnattr_setschedpolicy() functions conform to IEEE Std 1003.1-2001 (``POSIX.1''). HISTORY
The posix_spawnattr_getschedpolicy() and posix_spawnattr_setschedpolicy() functions first appeared in FreeBSD 8.0. AUTHORS
Ed Schouten <ed@FreeBSD.org> BSD
March 24, 2008 BSD