LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-16-2006, 02:50 AM   #1
_hadi_
LQ Newbie
 
Registered: Dec 2006
Location: Tehran, Iran
Distribution: Ubuntu
Posts: 5

Rep: Reputation: 0
Force Linux to run shell script in FIFO manner


Dear All,
I have a shell script that can be run by apache.
I want these scripts execute in FIFO (First IN First Out) manner.
Any ideas?

Last edited by _hadi_; 12-16-2006 at 02:53 AM.
 
Old 12-16-2006, 08:24 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Not quite sure what you mean.

Commands are executed synchronously unless you tell them not to be.

e.g. If you had a script that said:
ls -l
df -h
cat /etc/fstab

It would not start the "df -h" until the "ls -l" had completed. It would not start the "cat /etc/fstab" until the "df -h" had completed.

You can make it asynchronous by putting ampserand (&) after the commands:
ls -l &
df -h &
cat /etc/fstab &
All 3 commands would start as soon as the prior one had started without waiting for a return status.

Some commands do background themselves. You could put in sleep statements to wait for them to complete:

ls -l
sleep 10
df -h
sleep 5
cat /etc/fstab

It would wait 10 seconds after ls -l to start the df -h. It would wait five seconds after the df -h to start the cat /etc/fstab.

Can you detail exactly what you're trying to do?
 
Old 12-17-2006, 01:42 AM   #3
_hadi_
LQ Newbie
 
Registered: Dec 2006
Location: Tehran, Iran
Distribution: Ubuntu
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for your reply.
I have a script file myscript.sh.
I can run it like myscript.sh & in the background.
I can run more than one instances of myscript.sh & in the background.
I want these instances be run in FIFO manner.
 
Old 12-17-2006, 02:12 AM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Instead of running them with the "&" run them without it. That way it won't run the second myscript.sh until the first one has completed. That is the say it is the "&" that is making them go at the same time. Taking it out will make them go one after the other.

You really don't want to run several copies of the same script at the same time anyway because it hammers your CPU due to contention for the same resources.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to run a shell script in the perl script sharad Linux - General 1 05-24-2006 03:23 AM
How to run SHELL script pito Linux - Newbie 4 12-17-2004 03:05 AM
Shell script to run pl/sql script. colly Linux - General 1 09-09-2004 06:49 AM
how do i run shell script? krt47 Linux - Newbie 4 08-02-2004 09:29 AM
how to run a shell script in Linux chandhru Linux - Newbie 2 09-27-2002 01:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration