process check


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers process check
# 1  
Old 06-16-2005
process check

does anyone know an easy way that at the beginning of your script you check to see if that process is already running? I think it would have something to do with ps but I may be making it more complicated than it has to be. If you have a script run say, every half hour, you would want to check and make sure that it isn't still running from the previous half hour and if it is exit out. does anyone know what I mean?
# 2  
Old 06-16-2005
"we" know exactly what you mean Smilie
If on Solaris, take a look at 'man fuser"
# 3  
Old 06-16-2005
what about something like this:

if [ -n "$(ps -ef | grep user | grep prog.sh)" ]
then
echo " Process is already running"
exit 0

it apparently throws me into an infinite loop and I must kill the process but am I close?
# 4  
Old 06-16-2005
nope, not close yet - I recommended looking into "fuser"

let's call this script kas.sh

and let's invoke it as:
(./kas.sh &); sleep 2;./kas.sh
Code:
#!/bin/ksh
#

thisFILE="$(whence ${0})"
progName="${0##*/}"

     myPID="$$"

     FUSERout=$(fuser ${thisFILE} 2>/dev/null)
     typeset -i numProc=$(echo "${FUSERout}" | nawk '{print NF}')
     if [[ "${numProc}" -gt 1 ]]; then
        echo "${progName}: another instance(s) of [${thisFILE}] is currently sti
ll running [$(echo ${FUSERout} | sed -e 's/  */ /g')] - exiting THIS [${myPID}]run."
        exit 1
     fi

     sleep 5
     echo "finished->[${myPID}]"

# 5  
Old 06-16-2005
lsof is a utility just like fuser on some other unix systems.
# 6  
Old 06-17-2005
hi k@ssidy

you had tried with

ps -ef | grep <user> | grep <processname>

but this would always return true since grep is a process

try,
ps -ef | grep <user> | grep <processname> | grep -v grep
# 7  
Old 06-17-2005
I thought you were right about adding the grep -v grep part but it is always returning process already running and it exits out. I can't seem to get a grasp on the fuser option either but I am still giving it a try in a copy of my script, I really thought I was close with the approach I was using (ps -ef ...), any other suggestions?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How a process can check if a particular process is running on different machine?

I have process1 running on one machine and generating some log file. Now another process which can be launched on any machine wants to know if process1 is running or not and also in case it is running it wants to stream the logs file generated by process1 on terminal from which process2 is... (2 Replies)
Discussion started by: saurabhnsit2001
2 Replies

2. UNIX and Linux Applications

How to check if process is running?

Hi I would like to check if an instance of a script is already running. I've seen many different examples, but I haven't the slightest idea as to how to do this. Can you please help. Thank you. (5 Replies)
Discussion started by: ladyAnne
5 Replies

3. Shell Programming and Scripting

Check if Process is running

Hi , I have a csh code below which check the process if it's running. Can any expert advise me on the following: 1) what does this notationmean ">!" and how is it different from the append ">" notation ? 2) how does "setenv" work in this code ? # Check whether there is a running... (3 Replies)
Discussion started by: Raynon
3 Replies

4. Shell Programming and Scripting

Check process

Hi.. I have this code which tells me that if a process is running or not. Actually someone on this forum help me to do it. :) But now If i want to check if the process is not running for more than 10 minutes. Does anyone know the code or syntax that checks if a process is not running for some... (1 Reply)
Discussion started by: kanexxx
1 Replies

5. Solaris

Check CRON Process

How to find what are the cron jobs which are running at any instant on a Solaris server ??? The job can be scheduled from any id but still would like to list all the cron jobs which are running on the server ??? (2 Replies)
Discussion started by: helper
2 Replies

6. UNIX for Dummies Questions & Answers

Check whether a process is alive or not

Hi Everybody I have small requirement that needs to be implemented in shell script. Currently i have shell script which invokes a java process say "Process A" which runs in background. If some one tries to invoke again the same shell script , then there should be some mechanism inside the... (23 Replies)
Discussion started by: appleforme1415
23 Replies

7. UNIX for Dummies Questions & Answers

Check the process

Except the command "top" , is there other function / tool is used to check the process status in the system like 1. what process are running ? 2. how the CPU are allocating ? 3. how many swap is using ? 4. " Thx. (1 Reply)
Discussion started by: ust
1 Replies

8. Shell Programming and Scripting

check the process

how to kill the process that are idle over 30 minutes ? thx (2 Replies)
Discussion started by: ust
2 Replies

9. UNIX for Advanced & Expert Users

Check the process

I want to find the pid ( by ps ) that has already run over 30 seconds , I know ps only show the minute/hour . eg. the start time of the below process are 15:19 / 15:20 , but I don't know the exact time ( in term of "second" ) it start to run ( I only know the hour and minute ) , if I want to... (2 Replies)
Discussion started by: ust
2 Replies

10. UNIX for Advanced & Expert Users

How to check Process Utilisation

Hi, Is there any way in Unix to check for the system usage processwise ?? I mean I wud like to get a listing of running processes along with their CPU / memory utilisation so that I can spot dangerous the space / memory eaters .. Thanks & regards, SNS (2 Replies)
Discussion started by: Sabari Nath S
2 Replies
Login or Register to Ask a Question