LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 02-09-2010, 11:23 AM   #1
sang_froid
Member
 
Registered: Oct 2006
Posts: 179

Rep: Reputation: 15
kill command


what does the following command do ?

kill -0 $PID 1> /dev/null 2> /dev/null
 
Old 02-09-2010, 11:33 AM   #2
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,753

Rep: Reputation: 88
0 is not a valid signal. I think it will check for the existence of process with $PID, routes errors and stdout to /dev/null and sets the return code to 1 if it was found and 0 if not.

echo $?
 
Old 02-09-2010, 11:37 AM   #3
sang_froid
Member
 
Registered: Oct 2006
Posts: 179

Original Poster
Rep: Reputation: 15
well man page of kill says that it will kill all processes belonging to that group...that is what made me confused..

If that be correct, then say if i run that code in proftpd, then it is going to kill all proftpd child processes so far as i believe.



Quote:
Originally Posted by crabboy View Post
0 is not a valid signal. I think it will check for the existence of process with $PID, routes errors and stdout to /dev/null and sets the return code to 1 if it was found and 0 if not.

echo $?
 
Old 02-09-2010, 11:44 AM   #4
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,753

Rep: Reputation: 88
Maybe the machine I tested on has an older version of kill, but kill -0 fails to kill anything.
 
Old 02-09-2010, 11:47 AM   #5
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,753

Rep: Reputation: 88
This is from the man page:
Quote:
If sig is 0, then no signal is sent, but error checking is still per-
formed.
I think what you read is regarding the PID:
Quote:
OPTIONS
pid... Specify the list of processes that kill should signal. Each pid
can be one of five things:

n where n is larger than 0. The process with pid n will be
signaled.

0 All processes in the current process group are signaled.
...
 
Old 02-09-2010, 11:50 AM   #6
amani
Senior Member
 
Registered: Jul 2006
Location: Kolkata, India
Distribution: 64-bit GNU/Linux, Kubuntu64, Fedora QA, Slackware,
Posts: 2,434

Rep: Reputation: Disabled
man kill says

0 0 n/a exit code indicates if a signal may be sent


(*buntu-9.10 )
 
Old 02-09-2010, 01:30 PM   #7
sang_froid
Member
 
Registered: Oct 2006
Posts: 179

Original Poster
Rep: Reputation: 15
I am just trying to find out what is this piece of code trying to do

Quote:
RUN=./file
OPT=
#OPT=-d

# Send output to...
OUTPUT=./time.cron
#OUTPUT=/dev/null

if [ -r mech.pid ]; then
PID=`cat mech.pid`
if [ -r /proc/$PID ]; then
exit 0
fi
if ( kill -0 $PID 1> /dev/null 2> /dev/null ); then
exit 0
fi
fi

# its not running...

echo >> $OUTPUT
echo "Mech restarted:" >> $OUTPUT
( date 2>&1 ) >> $OUTPUT
echo >> $OUTPUT
( $RUN $OPT 2>&1 ) >> $OUTPUT
 
Old 02-09-2010, 02:46 PM   #8
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,753

Rep: Reputation: 88
It is checking to see if the PID in the pid file is valid. kill -0 PID will return a 1 if the process with PID is alive and if so the script will exit. If not, it will restart the process.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
kill command vinaytp Linux - Newbie 3 12-07-2009 10:01 PM
kill command pulkitbajar Linux - Newbie 7 05-12-2009 07:19 PM
why we cannot kill process id 1 with command "kill -9 1" satyaredhat Linux - Newbie 7 03-11-2009 12:48 PM
Kill command could not kill Kanaflloric Linux - General 11 08-22-2005 07:18 AM
kill command... Sonny Linux - Newbie 2 01-28-2002 03:08 AM


All times are GMT -5. The time now is 08:40 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration