How to find the jobs running in background and stop | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

How to find the jobs running in background and stop

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-03-2006
srinivas_paluku srinivas_paluku is offline
Registered User
 
Join Date: Oct 2006
Last Activity: 23 June 2008, 11:39 AM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Bug 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.

Regards & Thanks in advance.
Srinivas
Sponsored Links
    #2  
Old 10-03-2006
srikanthus2002's Avatar
srikanthus2002 srikanthus2002 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 14 October 2011, 3:22 PM EDT
Location: Can u guess...!
Posts: 161
Thanks: 0
Thanked 0 Times in 0 Posts
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

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

Code:
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
Sponsored Links
    #3  
Old 10-24-2007
krk_555 krk_555 is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 5 September 2009, 4:04 PM EDT
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Guys,
How can i find the is the process is running in back ground.

Actually
    #4  
Old 10-24-2007
manas_ranjan's Avatar
manas_ranjan manas_ranjan is offline
Registered User
 
Join Date: Jul 2007
Last Activity: 18 April 2014, 7:12 AM EDT
Location: Amsterdam
Posts: 269
Thanks: 11
Thanked 0 Times in 0 Posts
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 ????
Sponsored Links
    #5  
Old 10-24-2007
krk_555 krk_555 is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 5 September 2009, 4:04 PM EDT
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
if a process is appending with & means its running in bg

like

script_1.sh &
echo $!

you will get the process id
Sponsored Links
    #6  
Old 01-28-2008
ShawnSMSU ShawnSMSU is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 29 January 2008, 1:10 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:

Code:
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

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!!
Sponsored Links
    #7  
Old 01-28-2008
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 22 April 2014, 10:09 PM EDT
Location: Foxborough, MA
Posts: 7,538
Thanks: 137
Thanked 538 Times in 505 Posts

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

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Command to stop all the cron jobs indira_s Shell Programming and Scripting 2 05-18-2012 04:47 PM
Waiting for an arbitrary background process (limiting number of jobs running) p.f.moore Shell Programming and Scripting 15 02-01-2010 04:36 AM
How to stop the script which is running in background Prateek007 Shell Programming and Scripting 3 11-23-2008 04:54 AM
background jobs exit status and limit the number of jobs to run GrepMe Shell Programming and Scripting 1 06-11-2007 06:56 PM
Issues with exit after running jobs in background hyennah Shell Programming and Scripting 1 04-03-2007 01:44 AM



All times are GMT -4. The time now is 02:42 AM.