LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 06-25-2008, 03:50 AM   #1
asihsh.nakul
LQ Newbie
 
Registered: Jun 2008
Location: india
Posts: 3

Rep: Reputation: 0
Unhappy What does kill -0 PID do?


dear all

im struck with question " What kill -0 PID do"

i have check many sites but the answer is same if the PID found it comes back to KONSOLE.... i want detailed answer

please help me

regards
nakul.ashish

Last edited by Tinkster; 06-25-2008 at 05:53 AM.
 
Old 06-25-2008, 05:17 AM   #2
antegallya
Member
 
Registered: Jun 2008
Location: Belgium
Distribution: Debian
Posts: 109

Rep: Reputation: 42
Hi,

according to the man pages :
Quote:
The signals listed below may be available for use with kill. When known constant, numbers and default behavior are shown.
Name Num Action Description
0 0 n/a exit code indicates if a signal may be sent
So, it does nothing, but the exit code of your "kill -0 PID" command just returns 0 if you can send a signal to PID, and returns 1 if you can't (don't have access or invalid PID)

regards,
Antegallya
 
Old 06-25-2008, 05:52 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,000
Blog Entries: 11

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
Hi,

welcome to LQ!
Quote:
i have check many sites but the answer is same if the PID found it comes back to KONSOLE.... i want detailed answer
But reading the man-page for kill could have saved you hours
of searching (or posting, for that matter) ;) ...

Quote:
Code:
man kill
SIGNALS
       The  signals  listed  below  may  be available for use with kill.  When
       known constant, numbers and default behavior are shown.

       Name     Num   Action    Description
       0          0   n/a       exit code indicates if a signal may be sent


Cheers,
Tink
 
Old 06-26-2008, 03:34 AM   #4
asihsh.nakul
LQ Newbie
 
Registered: Jun 2008
Location: india
Posts: 3

Original Poster
Rep: Reputation: 0
Post Thanks but i need more

Hi

dude thanks for the replying,

but as my training going on (system admin) so this I've already submitted to my TL can find some more....

Regards
Ashish Shankar


Quote:
Originally Posted by Tinkster View Post
Hi,

welcome to LQ!

But reading the man-page for kill could have saved you hours
of searching (or posting, for that matter) ...





Cheers,
Tink
 
Old 06-26-2008, 03:35 AM   #5
asihsh.nakul
LQ Newbie
 
Registered: Jun 2008
Location: india
Posts: 3

Original Poster
Rep: Reputation: 0
Hi

dude thanks for the replying,

but as my training going on (system admin) so this I've already submitted to my TL can find some more....

Regards
Ashish Shankar
 
Old 06-26-2008, 07:04 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967
please note we aren't here to do your homework for you...
 
Old 07-17-2012, 01:15 PM   #7
dsouza
LQ Newbie
 
Registered: Jun 2006
Posts: 3

Rep: Reputation: 0
Quote:
Originally Posted by Tinkster View Post
But reading the man-page for kill could have saved you hours
of searching (or posting, for that matter) ...
It's needless snarkiness like this that turns off many noobs and non-native speakers of English. If you really wanted to help, you could show him how to use a return code from "kill -0" in a script to determine the existence or non-existence of a process.

There is just a handful of man pages written with the end user in mind. The huge majority are shorthand for fellow coders.
 
Old 07-17-2012, 02:22 PM   #8
honeybadger
Member
 
Registered: Aug 2007
Location: India
Distribution: Slackware (mainly) and then a lot of others...
Posts: 853

Rep: Reputation: Disabled
man pages for common commands (man 1 i.e man section 1) are understandable to anyone (unless there is a language problems) and I think it should work.
some man pages (eg man 2 or man 3) definately need some technical know-how and for that you can post here.
 
Old 07-17-2012, 05:24 PM   #9
sharadchhetri
Member
 
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179

Rep: Reputation: 23
Exclamation

Quote:
Originally Posted by honeybadger View Post
man pages for common commands (man 1 i.e man section 1) are understandable to anyone (unless there is a language problems) and I think it should work.
some man pages (eg man 2 or man 3) definately need some technical know-how and for that you can post here.
As you are new to linux.keep these things always in practice.

(1) man pages (to know about what commands can do)
(2) check the logs (in troubleshooting)

cheers
 
Old 07-18-2012, 03:23 AM   #10
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967
He is NOT new to Linux. This question is FOUR YEARS OLD.
 
Old 07-18-2012, 11:19 AM   #11
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
I don't think that I got any wiser from reading the man page. Probably just me that thinks that I'm always allowed to (may) send a signal to a process. I mean, I can type the command kill -9 pid and press <enter>; the OS might not allow me to kill a process (or whatever), but it will tell me that when I issue the command; so why kill -0 pid first?

Below how I see that it can be used and it's a total waste of cpu cycles.
Code:
kill -0 pid && kill -9 pid
I agree that this thread should not have been woken up, but now it's alive again I like to know why kill -0 pid exists?
 
Old 07-18-2012, 06:18 PM   #12
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967
For the reasons above from 4 years ago...
 
Old 07-19-2012, 03:16 AM   #13
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
I think I finally figured out an example for myself that might be useful (but it took a while)

Code:
kill -0 $1
if [ $? -eq 1 ]; then
  echo "no permission to signal pid $1, script terminated"
  exit
fi
...
...
...
kill appropriate_signal_depending_on_process $1
The dots can be a modification of a config file for a background process; the 'kill' will inform the process that it needs to read the config again.

Any better examples?
 
Old 07-19-2012, 08:06 PM   #14
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,311

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
I think its there to differentiate between processes you can't signal because you don't have access/auth eg they are not yours (doesn't apply to root ) and processes you get a failure on because it either doesn't have a handler for that signal, or its incorrectly written.
 
Old 11-14-2012, 01:35 PM   #15
mfirth
LQ Newbie
 
Registered: Jul 2003
Location: Ipswich, UK
Distribution: Slackware 7.1 and 9.0
Posts: 4

Rep: Reputation: 0
Sorry to resurrect this again, but another possible use for "kill -0" (or more likely the system API equivalent) is to check the existence of a process before communicating with it in another way - e.g.

If service X writes its process ID into /var/run/X.pid, then you can use 'kill -0 `cat /var/run/X.pid`' to determine if the process for X is still running.

There are obviously other ways of doing it (e.g. checking for the PID in /proc, or using grep on the output of PS), but they are probably less elegant

Hope this is useful

Michael
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
What to do when kill -9 PID doesn't work klauswunderlich Linux - General 7 10-11-2011 09:47 PM
kill <pid> does not do anything moskito01 Linux - General 9 08-25-2009 01:20 PM
kill -9 and respawns as new pid jago25_98 Linux - Software 3 06-18-2007 03:05 PM
kill pid ekdya Debian 3 04-18-2006 06:04 PM
kill pid.... won't work with 'pid' variable given.. sachitha Programming 6 03-06-2006 08:48 PM


All times are GMT -5. The time now is 10:25 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 Google+: linuxquestions
Open Source Consulting | Domain Registration