How to find the jobs running in background and stop

Hi All,

I have requirement. I am running a job every 30mins. before starting the process, i need to check the process, if the process is still running then i need not trigger the process again, if it is not running then trigger the process again. I am using cron to trigger the shell script. Can you please help by telling the exact command. I am new to shell scriptiing. :slight_smile:

Regards & Thanks in advance.
Srinivas

Let us take below exampls as a script (urs_script)

4 S srikanth 20075 20074 0 75 0 - 1066 - 15:27 pts/10 00:00:00 usr_script

------------------------------------

FIND=`ps -elf | grep "usr_script" | grep -v grep`
if [ $? -eq 0 ]
then
	echo "process found'
	echo $FIND
	FINDPROC=`awk {print $4}`  # it reads forth column to find process id
	kill -9 $FINDPROC  # kills process id of the usr_scirpts procsses
else
	echo "process no found"
	#start your scirpt here
fi

go through this example

if any problem pls let me know to give proper solution

Hi Guys,
How can i find the is the process is running in back ground.

Actually

hey krk,

before checking how to find a process whether it is running in background or not ???? can you check and let us know, how to check whether any process is runnning irrespective of bg or fg ????

if a process is appending with & means its running in bg

like

script_1.sh &
echo $!

you will get the process id

This didn't work for me, can anyone see what needs to be changed? Here's my output:

process found
0 S userName 21426 1 0 40 20 ? 14409 ? 15:12:34 pts/2 0:06 rmiregistry 1199
awk: syntax error near line 1
awk: illegal statement near line 1

Thanks!!

FINDPROC=`echo "${FIND}" | awk '{print $4}'` 

Awesome! Thanks for the quick response too.