usage of ps -ef


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users usage of ps -ef
# 1  
Old 07-08-2008
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.
# 2  
Old 07-08-2008
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  
Old 07-08-2008
I tired that too..
That is giving correctly..

wat else can be done ...
# 4  
Old 07-08-2008
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:/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


Last edited by zaxxon; 01-20-2009 at 05:46 AM.. Reason: removed a domain name
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Memory usage per user,percent usage,sytem time in ksh

Let's say i have 20 users logged on Server. How can I know how much memory percent used each of them is using with system time in each user? (2 Replies)
Discussion started by: roy1912
2 Replies

2. Shell Programming and Scripting

Usage of $(

I recently came across this construct that i am not able to understand. ex: cat $(grep -l 'HELLO' *) the above command prints out the contents of the file if HELLO string is present in the file. I am not able to understand the usage of "$(" here.. can anybody help me understand this? $anything... (2 Replies)
Discussion started by: sreeharshasn
2 Replies

3. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

4. Shell Programming and Scripting

Confused with the usage of one variable usage

Hi All I am not able to understand the usage of d# in the below variable declaration. FILE_LOC contains the directory path And also help me to know about what will be saved in the variable j. Thanks!!! j=${d#${FILE_LOC}/} (2 Replies)
Discussion started by: mohanm
2 Replies

5. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

6. Solaris

current CPU usage, memory usage, disk I/O oid(snmp)

Hi, I want to monitor the current cpu usage, monitor usage , disk I/o and network utlization for solaris using SNMP. I want the oids for above tasks. can you please tell me that Thank you (2 Replies)
Discussion started by: S_venkatesh
2 Replies

7. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

8. Shell Programming and Scripting

Disk Usage

Hi, I want to retrieve the directory in the shell script that is using maximum space on the disk.I was using du command but it displays all the directories that are using the space on the disk.How can retrieve the only directory which uses the maximum space on the disk?? Thanks in advance. ... (4 Replies)
Discussion started by: harikamamidala
4 Replies

9. Programming

CPU usage and memory usage

Please tell me solaris functions/api for getting following information 1- Function that tells how much memory used by current process 2- Function that tells how much memory used by all running processes 3- Function that tells how much CPU is used by current process 4- Function that tells how... (1 Reply)
Discussion started by: mansoorulhaq
1 Replies

10. Programming

Monitor CPU usage and Memory Usage

how can i monitor usages of CPU, Memory, Hard disk etc. under SUN Solaries through a c program or java program i want to store that data into database so i can show it graphically thanks in advance (2 Replies)
Discussion started by: Gajanad Bihani
2 Replies
Login or Register to Ask a Question