LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-20-2007, 08:33 PM   #1
TomCruise2002
LQ Newbie
 
Registered: Sep 2002
Posts: 12

Rep: Reputation: 0
Preventing processes running concurrently - using ps


I have a BASH script that is activated by CRON. Inside this script there are other BASH scripts that will be running from within.

The scripts process files. The schedule is every half hour. If one script is already running, I cannot allow another one to run. This can happen if there are a lot of files to process at one time.

TO avoid this, I put something like this in each parent and child script:

#check if the same process is running
numpid=`/bin/ps -ef|grep convxml | grep -v grep|wc -l`
echo "convxml number of processes::"$numpid
if [ $numpid -gt 3 ] ; then
echo convxml already running..Terminating
exit 1
fi

Now, I am having a problem with this because $numpid is giving different values each time, when I thought it should just be giving one value. I have no idea why each time it is giving different values when each time there is no other process running.

This makes it difficult for me to check if there are any other processes running. When I dump `ps -ef` to a text file, within the script, I only see one occurence of 'convxml.sh' so why is it showing different values each time?

Any ideas?

convxml.sh number of processes:: 3
convxml.sh number of processes:: 2
convxml.sh number of processes:: 2
convxml.sh number of processes:: 2
convxml.sh number of processes:: 5
convxml.sh number of processes:: 2
convxml.sh number of processes:: 2
convxml.sh number of processes:: 5
convxml.sh number of processes:: 6
convxml.sh number of processes:: 2
 
Old 03-21-2007, 01:10 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
Your shell script is convxml.sh. If it contains a command with a name like "convxml" or "convxml.pl" then it would count those because you're just grepping for "convxml" and not "convxml.sh".

It is fairly common for users to name their scripts after the binary they're wrapping it around so I wouldn't be surprised to find you were calling something called convxml (with or without a suffix) within the script itself.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Preventing multiple instances of a shell script from running concurrently Dave Lerner Programming 17 04-21-2020 12:53 PM
Run 4-processes concurrently using fork() ugp Programming 1 02-26-2006 08:49 AM
Preventing root processes... znapper Linux - Security 5 03-18-2004 12:18 PM
need running processes amrogers3 Linux - Newbie 4 02-24-2004 08:23 AM
Running processes Nicksan Linux - Software 1 05-30-2003 09:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:48 AM.

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