Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I'm trying to kill a process which I don't own. I've thought about calling an 'su <newuser>' in the script and then calling kill() but am not sure how to interact with the new shell or how to input the password for the new user. Any ideas? Sunil
  • Comment on calling kill on a different user's process

Replies are listed 'Best First'.
Re: calling kill on a different user's process
by rob_au (Abbot) on Dec 16, 2002 at 12:42 UTC
    This is more of a system security issue rather than a perl issue per se.

    The real and effective user account under which a perl script is executed can be modified by means of the real and effective user ID variables ($<, $>, $( and $)) listed in perlvar. Note that these variables can only be set, changing the corresponding process user ID variables, on machines supporting the associated set[re][ug]id() routine. This method of modifying real and effective user rights however may require the invocation of the script with heightened rights (suid).

    An alternate approach, particularly well suited to an environment where suid scripts are not appropriate, is to make use of sudo - This command allows administrators to grant permissions to users to execute priviledged commands without having to su to root. The advantage with this command offers in this scenario however is that, when configured as such, it allows priviledged commands to be executed by users without prompting for a password.

     

    perl -le 'print+unpack("N",pack("B32","00000000000000000000000111111101"))'