The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Notification from Background jobs vibhor_agarwali UNIX for Advanced & Expert Users 19 06-20-2007 06:29 AM
background jobs exit status and limit the number of jobs to run GrepMe Shell Programming and Scripting 1 06-11-2007 07:56 PM
Issues with exit after running jobs in background hyennah Shell Programming and Scripting 1 04-03-2007 02:44 AM
Background jobs Jeremiorama High Level Programming 1 11-25-2005 09:48 AM
background jobs qsi Shell Programming and Scripting 4 11-24-2004 05:45 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-03-2006
srinivas_paluku srinivas_paluku is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 5
Smile 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
  #2 (permalink)  
Old 10-03-2006
srikanthus2002's Avatar
srikanthus2002 srikanthus2002 is offline
Registered User
  
 

Join Date: Sep 2006
Location: Can u guess...!
Posts: 160
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
  #3 (permalink)  
Old 10-24-2007
krk_555 krk_555 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 14
Hi Guys,
How can i find the is the process is running in back ground.

Actually
  #4 (permalink)  
Old 10-24-2007
manas_ranjan's Avatar
manas_ranjan manas_ranjan is offline
Registered User
  
 

Join Date: Jul 2007
Location: Amsterdam
Posts: 177
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 ????
  #5 (permalink)  
Old 10-24-2007
krk_555 krk_555 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 14
if a process is appending with & means its running in bg

like

script_1.sh &
echo $!

you will get the process id
  #6 (permalink)  
Old 01-28-2008
ShawnSMSU ShawnSMSU is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 2
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!!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0