LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 02: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 04:53 AM.
 
Old 06-25-2008, 04: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, 04:52 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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, 02: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, 02: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, 06:04 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

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

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, 01:22 PM   #8
honeybadger
Member
 
Registered: Aug 2007
Location: India
Distribution: Slackware (mainly) and then a lot of others...
Posts: 855

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, 04: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, 02:23 AM   #10
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
He is NOT new to Linux. This question is FOUR YEARS OLD.
 
Old 07-18-2012, 10:19 AM   #11
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

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, 05:18 PM   #12
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
For the reasons above from 4 years ago...
 
Old 07-19-2012, 02:16 AM   #13
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

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, 07:06 PM   #14
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,364

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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, 12: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



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 08:47 PM
kill <pid> does not do anything moskito01 Linux - General 9 08-25-2009 12:20 PM
kill -9 and respawns as new pid jago25_98 Linux - Software 3 06-18-2007 02:05 PM
kill pid ekdya Debian 3 04-18-2006 05:04 PM
kill pid.... won't work with 'pid' variable given.. sachitha Programming 6 03-06-2006 07:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:23 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration