http://www.perlmonks.org?node_id=644927

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

Hello Monk's,

i've written a simple cgi script so i can kill processes on a linux server.
the problem is the process don't get killed at all.
script is owned by the running oser of the process and this user is allowed to kill processes.

a hint, or a slam with a tree woud be nice ;)

 
below is the kill function,that is triggered when u hit a button.

sub exec_restart { my $pids = param('pids'); my @pid = split(";",$pids); kill -9,@pid; print header; print qq(<HTML> <HEAD> <TITLE>CONSOLE 0.1</TITLE> </HEAD> <BODY> <p><div align="center">killed... $pids</div></p> </BODY> </HTML>); }

kind regards ultibuzz

Replies are listed 'Best First'.
Re: killing linux process with CGI
by moritz (Cardinal) on Oct 15, 2007 at 13:13 UTC
    If you don't do some serious configuration magic, the script is run as the www or www-data user by apache, not as the owner of the script.

    Which explains why you don't have the permission to kill scripts other than those with user www(-data).

      You should confirm this by printing the $< and $> values from your CGI script. One is the "real" user id (in numerical form), one is the "effective" user id. I'm expecting that neither one is set to the ID you expect.

      --
      [ e d @ h a l l e y . c c ]

      scriped is owned by www-data, and process running also by www-data
Re: killing linux process with CGI
by northwind (Hermit) on Oct 15, 2007 at 14:42 UTC
Re: killing linux process with CGI
by lorn (Monk) on Oct 15, 2007 at 13:43 UTC

    You can run apache with root, but need to compile with -DBIG_SECURITY_HOLE :)

    If you really need that, you can use a database cgi application, and then run a cron every 5 minutes that read the database and kill the process, and that cron run as root

    i'm not recommend anything, you cannot fix the problem, instead of kill the process?

    UPDATE: Users explain more thing, while i was writing this, please disregard

Re: killing linux process with CGI
by zentara (Archbishop) on Oct 15, 2007 at 14:25 UTC
    Just an idea that may not be suitable in your particular case. Investigate su and sudo. I have no idea how your server is setup, it can be complicated or impossible. Google and groups.google search for "sudo cgi" etc. Usually you need suexec running, so that cgi scripts get run as the user of the homedir. Sudo is usually preferred nowadays, since it is more restrictive(safer), where you specify what can be run , and by who, in a sudoers configuration file ( usually /etc/sudoers)

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      im using sudo, good tip to use it here ;)
Re: killing linux process with CGI
by blue_cowdawg (Monsignor) on Oct 15, 2007 at 16:35 UTC

    First off you should never be sending a signal 9 to a process unless prior attempts with other signals have falled (as has been pointed out to you in this thread) and secondly the parameter you need to send should have been a positive integer not a negative one. See kill.

    When you are passing the signal number from the shell the "-" signifies an optional parementer is being passed, not the signedness of the number of the signal.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: killing linux process with CGI
by tinita (Parson) on Oct 16, 2007 at 08:19 UTC
    additionally to the other comments about kill -9:
    kill -9,@pid;
    you should check the return value and the error message. why don't you want to know why it failed?
    kill -9, @pid or die "Could not kill: $!";
Re: killing linux process with CGI
by ultibuzz (Monk) on Oct 15, 2007 at 14:08 UTC
    both nummers are equal and the number of www-data.
    i thought of that i setup a sock listener on linux and send a signal through cgi to the listner, just found it in cookbook,server/client.

    update: sending signal via cgi to listner is working and process get killed.
    thx alot for the helpfull hints, liek the db thingy and the user variables(neverheared of them befor :) )
    kd ultibuzz
Re: killing linux process with CGI
by ultibuzz (Monk) on Oct 16, 2007 at 07:06 UTC
    thx for the hint with the kill 1,2 etc, tbh i didn't know thats bad to kill with 9
    thx to point out the - thing

    kd ultibuzz