kill 0

Discussion in 'Perl Misc' started by Brandon Metcalf, Jul 26, 2005.

  1. I'm seeing a behavior with using "kill 0,$pid" to determine if a
    process is running that I didn't expect. It seems that only root can
    correctly get the status on processes that root or another user that
    is different from the one calling kill() owns. For example,

    $ whoami
    bmetcalf
    $ ps -ef|grep gdm
    root 965 1 0 Jul19 ? 00:00:00 /usr/bin/gdm
    root 978 965 0 Jul19 ? 00:00:00 /usr/bin/gdm
    root 979 978 0 Jul19 ? 00:37:20 /usr/X11R6/bin/X :0 -deferglyphs 16 -nolisten tcp -audit 0 -auth /var/lib/gdm/:0.Xauth -nolisten tcp vt7
    bmetcalf 24443 23845 0 09:19 pts/5 00:00:00 grep gdm
    $ perl -le '$a = kill 0,965;print $a'
    0
    $ su
    Password:
    # perl -le '$a = kill 0,965;print $a'
    1

    Is this the expected behavior? I'm sure it is since every platform
    and version of Perl I've tried behave the same way.

    --
    Brandon
    Brandon Metcalf, Jul 26, 2005
    #1
    1. Advertising

  2. Brandon Metcalf

    Guest

    Brandon Metcalf <> wrote:
    > I'm seeing a behavior with using "kill 0,$pid" to determine if a
    > process is running that I didn't expect. It seems that only root can
    > correctly get the status on processes that root or another user that
    > is different from the one calling kill() owns. For example,
    >

    ....
    >
    > Is this the expected behavior? I'm sure it is since every platform
    > and version of Perl I've tried behave the same way.


    Given the docs for kill, it is the behavior I would expect (** mine):

    If SIGNAL is zero, no signal is sent to the process. This
    is a useful way to check that the process is alive and
    **hasn't changed its UID.** See perlport for notes on the
    portability of this construct.

    And by all means, do see perlport.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Jul 26, 2005
    #2
    1. Advertising

  3. On 2005-07-26, <> wrote:
    > Brandon Metcalf <> wrote:
    >> I'm seeing a behavior with using "kill 0,$pid" to determine if a
    >> process is running that I didn't expect. It seems that only root can
    >> correctly get the status on processes that root or another user that
    >> is different from the one calling kill() owns. For example,
    >>

    > ...
    >>
    >> Is this the expected behavior? I'm sure it is since every platform
    >> and version of Perl I've tried behave the same way.

    >
    > Given the docs for kill, it is the behavior I would expect (** mine):
    >
    > If SIGNAL is zero, no signal is sent to the process. This
    > is a useful way to check that the process is alive and
    > **hasn't changed its UID.** See perlport for notes on the
    > portability of this construct.
    >
    > And by all means, do see perlport.


    Sure, I looked at perlport but didn't see anything that explained what
    I'm seeing. Also, I don't see anything in the documentation for
    kill() what would explain this behavior. You highlighted "hasn't
    changed its UID", but I don't understand what that has to do with the
    problem.


    --
    Brandon
    Brandon Metcalf, Jul 26, 2005
    #3
  4. On 2005-07-26, Brandon Metcalf <> wrote:
    > On 2005-07-26, <> wrote:
    >> Brandon Metcalf <> wrote:
    >>> I'm seeing a behavior with using "kill 0,$pid" to determine if a
    >>> process is running that I didn't expect. It seems that only root can
    >>> correctly get the status on processes that root or another user that
    >>> is different from the one calling kill() owns. For example,
    >>>

    >> ...
    >>>
    >>> Is this the expected behavior? I'm sure it is since every platform
    >>> and version of Perl I've tried behave the same way.

    >>
    >> Given the docs for kill, it is the behavior I would expect (** mine):
    >>
    >> If SIGNAL is zero, no signal is sent to the process. This
    >> is a useful way to check that the process is alive and
    >> **hasn't changed its UID.** See perlport for notes on the
    >> portability of this construct.
    >>
    >> And by all means, do see perlport.

    >
    > Sure, I looked at perlport but didn't see anything that explained what
    > I'm seeing. Also, I don't see anything in the documentation for
    > kill() what would explain this behavior. You highlighted "hasn't
    > changed its UID", but I don't understand what that has to do with the
    > problem.


    OK. This explains it:

    $ ps -ef|grep gdm
    root 965 1 0 Jul19 ? 00:00:00 /usr/bin/gdm
    root 978 965 0 Jul19 ? 00:00:00 /usr/bin/gdm
    root 979 978 0 Jul19 ? 00:40:01 /usr/X11R6/bin/X :0 -deferglyphs 16 -nolisten tcp -audit 0 -auth /var/lib/gdm/:0.Xauth -nolisten tcp vt7
    bmetcalf 25710 25677 0 11:45 pts/13 00:00:00 grep gdm
    $ perl -le 'kill 0,965 or print $!'
    Operation not permitted

    So, one has to have permission to actually send a signal 0.

    --
    Brandon
    Brandon Metcalf, Jul 26, 2005
    #4
  5. On 2005-07-26, Jim Gibson <> wrote:
    > In article <20050726113448.218$>, <>
    > wrote:
    >
    >> Brandon Metcalf <> wrote:
    >> > I'm seeing a behavior with using "kill 0,$pid" to determine if a
    >> > process is running that I didn't expect. It seems that only root can
    >> > correctly get the status on processes that root or another user that
    >> > is different from the one calling kill() owns. For example,
    >> >

    >> ...
    >> >
    >> > Is this the expected behavior? I'm sure it is since every platform
    >> > and version of Perl I've tried behave the same way.

    >>
    >> Given the docs for kill, it is the behavior I would expect (** mine):
    >>
    >> If SIGNAL is zero, no signal is sent to the process. This
    >> is a useful way to check that the process is alive and
    >> **hasn't changed its UID.** See perlport for notes on the
    >> portability of this construct.

    >
    > And from the 'man kill' page:
    >
    > "Only the super-user may send signals to other users' processes."



    Sure, I read that as well. But Perl's implementation of signal 0 is
    special in that it doesn't actually send a signal to the process. It
    simply checks to see if it's alive. It doesn't seem that special
    permissions would be required to check the existence of a process.

    But, per my last post, proper permissions are required.

    --
    Brandon
    Brandon Metcalf, Jul 26, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chintan jajal via .NET 247

    Delegate Endinvoke Kill thread

    chintan jajal via .NET 247, May 24, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    6,838
    Richard Grimes [MVP]
    Jun 6, 2005
  2. Replies:
    0
    Views:
    638
  3. Isidro Vila Verde

    Kill and Signals

    Isidro Vila Verde, Nov 16, 2003, in forum: Perl
    Replies:
    1
    Views:
    657
    Roy Johnson
    Nov 20, 2003
  4. Carlo Filippini

    Kill win32 process

    Carlo Filippini, Jan 7, 2004, in forum: Perl
    Replies:
    0
    Views:
    1,078
    Carlo Filippini
    Jan 7, 2004
  5. Brian
    Replies:
    1
    Views:
    750
    Mothra
    May 25, 2004
Loading...

Share This Page