![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| CPU usage and memory usage | mansoorulhaq | High Level Programming | 1 | 08-09-2007 01:55 PM |
| Getting CPU Usage | WG1 | Shell Programming and Scripting | 4 | 05-01-2006 05:07 AM |
| Monitor CPU usage and Memory Usage | Gajanad Bihani | High Level Programming | 2 | 03-09-2005 04:35 AM |
| cpu usage | sushaga | Filesystems, Disks and Memory | 0 | 04-06-2002 05:46 AM |
| CPU usage | Karen | UNIX for Dummies Questions & Answers | 2 | 11-04-2001 04:50 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
usage of ps -ef
Hi,
I can have only one instance of my script running at any point of time. So I have : SCRIPT_NAME=$0 if [ `ps -ef | grep " ${SCRIPT_NAME}" | grep -v "grep" | wc -l` -gt 1 ]; then echo "The process $0 is already running. Aborting the current instance of the job $0" exit 1 fi And in the last line of the script i had given exit 0 At times, though the script is not running, i get an error "The process is already running ..." and my script get aborted. So wat can be done for this ? My requirement is I will scheudle this scirpt in autosys and will be executed every half an hour. And only one instance of the script should be executed at any point of time. Can any one please help me ?? thanks in advance. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Echo $SCRIPT_NAME and compare it what ps -ef give as output. Maybe they are slightly different and so grep can't find it that way. Maybe you got to parse or escape the leading ./ when you call it.
|
|
#3
|
|||
|
|||
|
I tired that too..
That is giving correctly.. wat else can be done ... |
|
#4
|
|||
|
|||
|
Your script works - I added an infinite loop so I have that script constantly running in the background. Started it with nohup & in the background and tried to start that script again:
Code:
root@isau02:/data/tmp/testfeld> ./loop.ksh
exit code: 0
script name: ./loop.ksh
The process ./loop.ksh is already running. Aborting the current instance of the job ./loop.ksh
root@isau02:/data/tmp/testfeld> ps -ef| grep -i loo
root 29647 32139 0 09:25 pts/0 00:00:00 /usr/bin/ksh ./loop.ksh
root 29685 29659 0 09:26 pts/1 00:00:00 grep -i loo
root@isau02.debeka.de:/data/tmp/testfeld> cat loo*
#!/usr/bin/ksh
typeset -i A=0
SCRIPT_NAME=$0
if [ `ps -ef | grep " ${SCRIPT_NAME}" | grep -v "grep" | wc -l` -gt 1 ]; then
echo "exit code: $?"
echo "script name: ${SCRIPT_NAME}"
echo "The process $0 is already running. Aborting the current instance of the job $0"
exit 1
fi
while (( $A != 1 )); do
sleep 1
done
exit 0
|
|||
| Google The UNIX and Linux Forums |