Implementing Queue Using Shell scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Implementing Queue Using Shell scripts
# 1  
Old 05-04-2010
Implementing Queue Using Shell scripts

HI
I want to implement a control mechanism using Shell scripts .The intention is to have controlled number of jobs running in parallel

External process will kickstart 40 jobs in parallel .All the 40 jobs will call the same generic script with different parameter values .But at a time only 2 should run ( In extended version of this i will dynamically change the value say to 5 or 10 ) .

What i tried to implement was , with in the generic script i will create a ctl file (CTL files names are unique with same extension) If the number of CTL files is more than or equal to ( -ge 2) , then i wil sleep the job .Else will run it .The problem is when 40 jobs comes back from sleep at the same time , the chances of two or process taking control is high .How can i restrict it ?

---------- Post updated 05-04-10 at 11:48 AM ---------- Previous update was 05-03-10 at 05:27 PM ----------

Any solutions ? What is the best way to implements the queuing mechanism in Shell scripts
# 2  
Old 05-04-2010
Don't bump up and don't cross-post
# 3  
Old 05-04-2010
There's probably lots of ways. One at a time is easy; anything that only one process can succeed at can be used as a locking mechanism, like mkfifo. Each process runs 'mkfifo /tmp/myfifo', if it succeeds, it has control until it deletes the fifo. if it doesn't, sleep a second then retry. Simple but not the most efficient, and not precisely a queue.

Two at a time is harder. Shell script doesn't have good mechanisms for tracking multiple children simultaneously, not in a manner to tell your script which child just terminated. It'd be possible with an arrangements of fifos to communicate between child and controller, but not trivial, and prone to breaking down when processes terminate unexpectedly.

It'd be simple enough to do and control with a makefile, if you have make.
# 4  
Old 05-04-2010
Hi.

I think post #5 of https://www.unix.com/unix-advanced-ex...2-xargs-p.html addresses the topic using GNU xargs -- not just on Linux, but ported to an HP ... cheers, drl
# 5  
Old 05-04-2010
You can probably do what you want to do using ksh93's co-process facilities.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Implementing linked list in shell scripting

Hello Experts, Is it possible to implement linked list in shell scripting? is yes then how can we do it? Any working example is highly appreciated. Thanks in advance. (4 Replies)
Discussion started by: mukulverma2408
4 Replies

2. Shell Programming and Scripting

Implementing Listagg like function in shell

Hi, Basically what I am trying to do is making multiple fields of the same type comma-separated. i.e. for a data like this: B00000 abc B00001 abc,def B00001 ghi B00001 jkl B00002 abc B00002 def B00003 xyz Output should be like: B00000 abc B00001 abc,def,ghi,jkl... (20 Replies)
Discussion started by: prohank
20 Replies

3. Shell Programming and Scripting

Shell Script for Websphere MQ Queue Manager start/stop

Hello All, I am completely new to shell scripting. I had to write a script that starts and stop the queue manager in Websphere MQ. We are on Linux 64-bit patform. The script should stop the queue manager and all the processes related to websphere MQ. It should be a clean stop. Once the queue... (3 Replies)
Discussion started by: pady1224
3 Replies

4. Shell Programming and Scripting

Need help implementing a timout in my Shell Script for RHEL6

Hey Guys, My problem: I have a script that will be querying the database every minute to see if it gets a response, the response its querying for is "UP" in a table i made called dbup in the database. Now, I am trying to add the component to implement a timeout if the script does not get a... (2 Replies)
Discussion started by: mo_VERTICASQL
2 Replies

5. Shell Programming and Scripting

calling 'n' number of shell scripts based on dependency in one shell script.

Hello gurus, I have three korn shell script 3.1, 3.2, 3.3. I would like to call three shell script in one shell script. i m looking for something like this call 3.1; If 3.1 = "complete" then call 3.2; if 3.2 = ''COMPlete" then call 3.3; else exit The... (1 Reply)
Discussion started by: shashi369
1 Replies

6. Homework & Coursework Questions

implementing mkdir, chdir, mv, pwd inside a shell !

1. The problem statement, all variables and given/known data: need to implement mkdir, chdir, mv, pwd given a shell.cpp directory.cpp and some other files this shell missing these commands, and i need to implement them inside the shell 2. Relevant commands, code, scripts,... (0 Replies)
Discussion started by: evantheking
0 Replies

7. Shell Programming and Scripting

shell script needed for mail queue notification

Hi shell experts, I would like to have a shell script running in a redhat server for monitoring the mailqueue status. I have already installed the qmHandle and I am using it to get a status of the mail queue in daily basis. I am executing the qmhandle in the cron. Now I am planning to execute... (10 Replies)
Discussion started by: Nightman
10 Replies

8. Programming

Implementing a shell in C

Hi, I am implementing a shell in C, with the following problem... Suppose the shell is invoked from the command line as >> myshell < test.in > test.out 2>&1 I have to execute the commands in test.in and redirect them to test.out How does one detect in the main function that the shell... (1 Reply)
Discussion started by: jacques83
1 Replies

9. Programming

need help in implementing simple interactive shell in C

hello all, i hv attached herewith my program to implement a simple interactive shell in C. no matter hw hard I try, I keep getting some errors. i need help - urgently !! proj1test7.c: In function `parseCommand': proj1test7.c:102: warning: assignment makes pointer from integer without a cast... (2 Replies)
Discussion started by: nix1209
2 Replies

10. Programming

Implementing a shell

I'm implementing a shell in C that supports piping, output redirection, and background processing, and a few other commands. I was wondering how I'd go about implementing the output redirection. So, I'd open a file and I'd fork and execute the command. But how would I get stdout into the file? Any... (10 Replies)
Discussion started by: ununium
10 Replies
Login or Register to Ask a Question