Re: service; ps & grep help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 2008-09-06 at 10:20 +1000, Cameron Simpson wrote:
> Going from reliable (trust the pid file) to the more cautious (trust
> the
> pid file, but check the pid has not been recycled (daemon dies without
> tiying up the pid file, new unrelated process gets the same pid)) you
> can do something like this:
> 
>   if [ -s /var/run/the-pid-file.pid ]
>   then
>     pid=`cat /var/run/the-pid-file.pid`
>     if [ -n "$pid" ]
>     then
>       pidcmd=`ps -p "$pid" -o command | awk '{print $1}'`
>       if [ "x$pidcmd" = 'xyour-java-command' ]
>       then
>         kill "$pid"
>       fi
>     fi
>   fi
> 
> i.e. check that the pid is still associated with the original daemon.

If you want to be picky, this is actually not enough. It just tells you
that process $pid is currently running a program with the same name as
the one you want. It may even be the same executable file, but it is not
necessarily the same process as before. Very unlikely, and it may not
matter to you, but it's worth being aware of.

One way round it might be to compare the file creation time
of /var/run/the-pid-file.pid with /proc/<pid>/starttime (some fiddly
arithmetic required here). Clearly the pid file should to be younger
than the process.

poc

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux