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

Hi Monks, I'm trying to kill a series of processes of which I'm not the owner. 'kill' doesn't let me do that unless I'm the superuser. How can I get over this. I've thought about calling a system(su <newuser>) but I'm not sure how to go about doing it this way. Sunil

Replies are listed 'Best First'.
Re: kill process
by rdfield (Priest) on Dec 12, 2002 at 12:45 UTC
    It's called "security". You're not supposed to be able to kill somebody else's processes. If it's something you must do from a non-priviledged account: be very, very careful. A couple of ways of doing this are sudo and setuid, but as I said, be very, very careful - what if someone else were to run this program?

    rdfield

Re: kill process
by Abigail-II (Bishop) on Dec 12, 2002 at 12:47 UTC
    Well, duh. Unix doesn't let you send signals to processes you don't own. Would you want other people to be able to kill your running processes?

    You could use 'su', but then you need to supply a password, which you cannot supply from the command line. Consider installing 'sudo', which you could configure such that you don't need to give a password to be able to issue the kill command as root (or as another users). But that would kind of defeat the purpose of having different users, doesn't it? It's certainly a security concern.

    Abigail

Re: kill process
by mce (Curate) on Dec 12, 2002 at 14:30 UTC
    my $pid=shift; system("sudo kill $pid");
    BUT, Caution: DON'T TRY THIS AT HOME :-)
    Bottomline: If the OS won't let you, perl won't either
    Updated after CB with diotalevi
    ---------------------------
    Dr. Mark Ceulemans
    Senior Consultant
    IT Masters, Belgium

      If anyone is curious the original post was a joke on `sudo rm -rf`. I considered the node because it was reckless. It wouldn't have worked anyway but that wasn't the real problem.

      __SIG__ use B; printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;