killing process through exec()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fahadist
Forum Newbie
Posts: 6
Joined: Sat Feb 02, 2008 8:40 am

killing process through exec()

Post by fahadist »

I am developing a webservice in PHP/Linux where I need to kill a process.

I tried using
exec("kill ".$pid);
and
exec("kill -KILL ".$pid);

but the return value was always 1 and the process still remained.

I wrote up a small shell script and have exec run that script. The script worked fine if invoked through command line but through php it didn't do anything.

I have a hunch that this is because killing a process might need root privilages so I updated the script to:

sudo -p my_passsword -u root kill $pid

yet it didn't work.

I still think the problem is access rights. question is how to solve it.

Any help will be greatly appreciated.

Sincerely
Fahad
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: killing process through exec()

Post by Christopher »

I think if you su to the user who runs the webserver and then sudo the process you want to kill, then you will be able to kill it.
(#10850)
fahadist
Forum Newbie
Posts: 6
Joined: Sat Feb 02, 2008 8:40 am

Re: killing process through exec()

Post by fahadist »

How do I do that in PHP?

after each exec the state will be lost.

Fahad
fahadist
Forum Newbie
Posts: 6
Joined: Sat Feb 02, 2008 8:40 am

Re: killing process through exec()

Post by fahadist »

Under which user rights does the apache/php server work?

Fahad
Post Reply