Introduction
I must admit, after a decade of working professionally with unix/linux, that I had never encountered kill -0 until last week.
What does the -0 signal do?
Nothing at all...
What is it useful for?
It returns 0 if the process exists, or 1 (and an error message on stderr) if it doesn't.
(Strictly, it returns whether a process can accept a signal, rather than whether it exists. Can anyone enlighten me on the difference? Kernel processes can accept signals - I didn't know that before I tried this - what can signaling kernel processes be used for?)
It's just a much nicer way of finding out whether a particular process id exists. Other alternatives I have seen/used include grepping through the output of ps -ef and checking for the existence of the appropriate directory in /proc.
Have a look at my entry on startup scripts for more details.
Example
chris@chris-laptop:~$ sleep 60 & [1] 1316 chris@chris-laptop:~$ kill -0 1316 # process id of the sleep command chris@chris-laptop:~$ echo $? 0 chris@chris-laptop:~$ kill -0 65535 # process does not exist bash: kill: (65535) - No such process chris@chris-laptop:~$ echo $? 1 chris@chris-laptop:~$ sudo kill -0 27835 # a kernel process chris@chris-laptop:~$ echo $? 0
Comments
Hi
Vimax and Vigrx is The Most Effective Penis Enlargement Pills on the market today, every single product is also guaranteed, and offers permanent results.
Real Estate | Homes | 3.5%
Real Estate | Homes | 3.5% FHA | Mortgage | Houses | 100% VA | Homes For Sale | Realtors | Zero Down USDA | Laguna Beach Houses For Sale | Lakewood New Homes | Half Percent Down | Lathrop Real Estate | Lincoln House For Sale | 203 K FHA | Lincoln MLS | Los Altos House | Conventional Loans | Mission Viejo House | Newark Houses For Sale | Jumbo Loans | Newport Beach MLS | Oakland New Homes | City Down Payment | Oakley House | Orange House For Sale | 2yr BK Discharge OK | Palm Desert House | Palm Desert MLS | <620 FICO with No 12 mo lates | Palm Springs California Homes | Palm Springs Realestate | 620+ FICO Ok | Roseville New Homes | San Clemente MLS | 6% Seller Credit OK | San Mateo MLS | San Pablo Real Estate | 30 Yr Fixed | Santa Clara MLS | Santa Cruz Realtor | 15 Yr Fixed | Stockton Houses For Sale | Suisun City Real Estate | 20 Yr Fixed | Yorba Linda House | Los Angeles Realtors | 5 Yr Adjustable | Sacramento Home | Newark Home | 7 Yr Adjustable | Long Beach Home | Lancaster Home | 10 Yr Adjustable
cheap pandora
is known as the jeweler with the name of the popular mythology is to assume that all accepted pandora beads by all age groups pandora necklaces and do it. pandora bangles Pandora a nice name for the first lady pandora sets in the beautiful world, cheap pandora beads it means a lot to the world. cheap pandora necklaces So, as jewelry under the name Pandora, could not be bad.
Pandora magic, cheap pandora bangles like Pandora Jewelry. The first time I see you do not see the shiny surface, but can pandora silver sets his magic.From Pandora bracelets, Pandora's Pass, you his unique custom can feel feel unique pattern. discount pandora bead And never forget the charm. discount pandora necklace And that is discount pandora bangle good can be individually tailored to your personality with Pandora jewelry. discount pandora sets individual differences have different tastes in a lot of questions and jewelry is one of them.
affordable homes in
affordable homes in California
Real Estate | Homes | 3.5% FHA | Mortgage | Houses | 100% VA | Homes For Sale | Realtors | Zero Down USDA | Concord Houses | Elk Grove Real Estate | Half Percent Down | Palo Alto Real Estate | Santa Cruz Real Estate | 203 K FHA | Costa Mesa Homes | Danville Homes | Conventional Loans | Davis Real Estate | Torrance Real Estate | Jumbo Loans | Westminster Homes | Woodland Real Estate | City Down Payment | Brentwood Home | Saratoga Real Estate | 2yr BK Discharge OK | Fullerton Homes | Lincoln House | <620 FICO with No 12 mo lates | Napa Real Estate | San Bernardino Real Estate | 620+ FICO Ok | Lake Forest Real Estate | Lancaster House | 6% Seller Credit OK | Mountain View Homes | Pleasanton Real Estate | 30 Yr Fixed | Sunnyvale Real Estate | Walnut Real Estate | 15 Yr Fixed | Antioch Real Estate | Ontario Homes For Sale | 20 Yr Fixed | Beaumont Real Estate | Campbell Real Estate | 5 Yr Adjustable | Cypress Real Estate | Hayward Real Estate | 7 Yr Adjustable | Livermore Real Estate | Mission Viejo Real Estate | 10 Yr Adjustable
abercrombie
You will be able pandora beads sale to acquirement teemingness from freshest pandora GB pandora necklaces sale and most belated assemblages pandora bangles sale of decorations bands buy pandora sets such antecedents capital buy pandora bead of the United Kingdom embellishes, buy pandora necklace beguiles, decorates, necklaces, chemical chain, anuluses, at factual sane tax. buy pandora bangle These business enterprise pandora sets sale comprises at present apportioning human being pandora silver beads coarse such U.S., Canada equally able because Britain.now pandora watchbands Great Britain constitutes Theia allot from allegoric and believed internet copiousness plus assumed posted jewelleries inwards Great Britain. pandora silver necklace A uncharacteristic of tolerance embodies systematically costs unforgettable pandora silver bangles inch our biography, cheap pandora sets I would as though to co-occurrence approximately jewelry bands to cor devotee along these February 14.
watches
17th session of Provincial Games Organizing Committee set upreplica watches11 years ago, a snow Bayern Allianz Jing Xian Qi Chi Manchester United-type Camp Nou lorereplica watchesBritish Government to increase up to 3.6 billion pounds per yearreplica watches14 people were injured in NATO helicopter crashreplica watchesExperts say the Russian terrorist forces create panic emphasis(L3.31)
シアリス | レビトラ | プロペシア | バイアグラ |
シアリス | レビトラ | プロペシア | バイアグラ | ルミガン | ケアプロスト | アボダート | ルミガン
Generic Viagra Cheap Generic
Generic Viagra
Cheap Generic Viagra
Generic Cialis
propecia
Generic Cialis
good post, thank you for
good post, thank you for sharing.
du doan bong da
du doan worldcup
Tiffany & Co Shop specialises
Tiffany & Co Shop specialises in superior sterling silver Tiffany Jewelry, Tiffany Shop provides hundreds of discount and fashion Tiffany Jewellery,
tiffany jewellery
tiffany co
tiffany
GHD Styler Hair Straightener - shop online for ghd stylers, the new limited edition purple ghd IV styler & gift set, ghd hair care products,
cheap ghd
ghd straighteners
ghd pink
ghd
ghd Hair Straighteners
the women like ugg boots,ugg cardy boots,you could buy cheap ugg boots from here!
ugg boots
uggs
Abercrombie
You will be able pandora beads sale to acquirement teemingness from freshest pandora GB pandora necklaces sale and most belated assemblages pandora bangles sale of decorations bands buy pandora sets such antecedents capital buy pandora bead of the United Kingdom embellishes, buy pandora necklace beguiles, decorates, necklaces, chemical chain, anuluses, at factual sane tax. buy pandora bangle These business enterprise pandora sets sale comprises at present apportioning human being pandora silver beads coarse such U.S., Canada equally able because Britain.now pandora watchbands Great Britain constitutes Theia allot from allegoric and believed internet copiousness plus assumed posted jewelleries inwards Great Britain. pandora silver necklace A uncharacteristic of tolerance embodies systematically costs unforgettable pandora silver bangles inch our biography, cheap pandora sets I would as though to co-occurrence approximately jewelry bands to cor devotee along these February 14.
There's a command for that.
You might be better off using the gnu program to do that, pidof.
http://en.wikipedia.org/wiki/Pidof
http://linux.die.net/man/8/pidof
There's a command for that.
Thanks, I hadn't come across pidof before.
Pidfiles typicaly use a
Pidfiles typicaly use a technique essay topics | abortion essay | marketing essay like this. Below is a bourne shell example from my backup script. The purpose is to prevent two backups from running at the same time.
narrative essay | persuasive essay
this is what pidfiles are for
Pidfiles typicaly use a technique like this. Below is a bourne shell example from my backup script. The purpose is to prevent two backups from running at the same time.
# exclusion pidfile=/tmp/backup.pid if test -f $pidfile then pid=`cat $pidfile` if kill -0 $pid then echo $0 running as $pid > STDERR exit 1 fi fi echo $$ > $pidfile"no such process" vs. "operation not permitted"
It shouldn't be a problem in most cases. Maybe it wasn't obvious, I was replying to this question in your post:
Strictly, it returns whether a process can accept a signal, rather than whether it exists. Can anyone enlighten me on the difference?
On the other hand, there might be cases where this will cause a problem. Imagine a startup script for some service that you normally start as a non-privileged user, a script that you also normally start as this very user. It is written so that it doesn't try to call `su'. And now someone accidentally starts this script as root - the service will probably seem to work fine until you try to restart it, then `kill -0' will give you an "operation not permitted" error.
The correct solution for this case is of course to change the startup script to that it tries to su to the non-privileged user if it is called as the wrong user. If it is called as root this will succeed, if it is called as another user then it will throw an error which should be noticed right away.
"no such process" vs. "operation not permitted"
Thanks, I understand now. Can you think of any problems with identifying running processes by looking at numeric directory entries in /proc?
Well, it's less portable, I
Well, it's less portable, I guess it would break on a BSDish system. My coworkers all use macs, so I should not break their development setup.
I first thought I could get a list of running processes from the OS to see if my processes are still running, but lhere seems to be no portable way to do that other than parsing the output from `ps' - which is of course fine for a shell script but looks like a hack if you're doing it in a "real" programming language. And of course you have to test your script against all different versions of `ps' that you might encounter. When you want to do this sort of thing getting the information from /proc starts to look like a really good idea.
Existing processes might not like to get signals from you...
You might get a failure if the process does not belong to you and you are not root. So kill -0 will fail, although the process exists: it just doesn't accept signals from you.
I used the same technique from a ruby startup script to determine if a previous instance was still running, so that I could delete the PID files safely otherwise.
Existing processes might not like to get signals from you...
Good point, but it shouldn't often be a concern, as most start scripts are run as root, even if some of the daemons run as less privileged users.
THanks!
This post enlightened me more! =)
Cudahy Ca Foreclosures | Ca Foreclosures 3.5% FHA Ca Foreclosures | DANVILLE Ca Foreclosures 100% VA DUBLIN Ca Foreclosures | GARDEN GROVE Ca Foreclosures Zero Down USDA LA PUENTE Ca Foreclosures | LIVERMORE Ca Foreclosures Half Percent Down MILPITAS Ca Foreclosures | MISSION VIEJO Ca Foreclosures 203 K FHA ORANGE Ca Foreclosures | PETALUMA Ca Foreclosures Conventional Loans REDONDO BEACH Ca Foreclosures | SAN LEANDRO Ca Foreclosures Jumbo Loans South Pasadena Ca Foreclosures | TURLOCK Ca Foreclosures City Down Payment TUSTIN Ca Foreclosures | WEST HOLLYWOOD Ca Foreclosures 2yr BK Discharge OK Aliso Viejo Ca Foreclosures | VA Mortgage Loan <620 FICO with No 12 mo lates VA Mortgage Loan | ARCADIA Ca Foreclosures 620+ FICO Ok DOWNEY Ca Foreclosures | FAIRFIELD Ca Foreclosures 6% Seller Credit OK FOLSOM Ca Foreclosures | LAGUNA NIGUEL Ca Foreclosures 30 Yr Fixed LOS BANOS Ca Foreclosures | MANTECA Ca Foreclosures 15 Yr Fixed MENLO PARK Ca Foreclosures | MORGAN HILL Ca Foreclosures 20 Yr Fixed NOVATO Ca Foreclosures | REDLANDS Ca Foreclosures 5 Yr Adjustable RICHMOND Ca Foreclosures | SAN RAFAEL Ca Foreclosures 7 Yr Adjustable UNION CITY Ca Foreclosures | WEST SACRAMENTO Ca Foreclosures 10 Yr Adjustable