ChrisMartino Posted August 25, 2009 Share Posted August 25, 2009 hey there i am currently coding my panel in php and i run a game server hosting company and i have multiple processes running with the same name how would i kill individual ones with a command in php? thanks Quote Link to comment https://forums.phpfreaks.com/topic/171801-killing-a-process-in-php/ Share on other sites More sharing options...
Maq Posted August 25, 2009 Share Posted August 25, 2009 Check out this note: http://us.php.net/manual/en/function.shell-exec.php#57215 Quote Link to comment https://forums.phpfreaks.com/topic/171801-killing-a-process-in-php/#findComment-905956 Share on other sites More sharing options...
ChrisMartino Posted August 25, 2009 Author Share Posted August 25, 2009 hey that just tells you how to execute a command i need to kill one but there are multiple tasks running with the same name i just want to kill a individual one Quote Link to comment https://forums.phpfreaks.com/topic/171801-killing-a-process-in-php/#findComment-906025 Share on other sites More sharing options...
ChrisMartino Posted August 25, 2009 Author Share Posted August 25, 2009 Dose anyone know + edit Quote Link to comment https://forums.phpfreaks.com/topic/171801-killing-a-process-in-php/#findComment-906045 Share on other sites More sharing options...
roopurt18 Posted August 25, 2009 Share Posted August 25, 2009 If you were running *nix you could do: ps aux | grep processname That will give you a listing of: pid (process_id) user ... user The pid column is what you're interested in; each process has a unique integer id. Once you know the pid you want to kill, like 5292: kill 5292 It's really the kill command you want to send through shell_exec(). I'm sure Windows has a similar functionality if you do some Googling. Quote Link to comment https://forums.phpfreaks.com/topic/171801-killing-a-process-in-php/#findComment-906048 Share on other sites More sharing options...
ChrisMartino Posted August 25, 2009 Author Share Posted August 25, 2009 this is for my control panel tho it needs to be automated so i need to kill the users server not everyones and all the processes that are running are all called "samp02Xsvr" Quote Link to comment https://forums.phpfreaks.com/topic/171801-killing-a-process-in-php/#findComment-906052 Share on other sites More sharing options...
ChrisMartino Posted August 25, 2009 Author Share Posted August 25, 2009 is there anyway to kill the individual process without killing all the samp02Xsvr's ? Quote Link to comment https://forums.phpfreaks.com/topic/171801-killing-a-process-in-php/#findComment-906217 Share on other sites More sharing options...
roopurt18 Posted August 26, 2009 Share Posted August 26, 2009 If the server is started with something like: samp02Xsvr -U someuser Then bash$ ps aux | grep samp02xSvr pid user command 1234 apache samp02Xsvr -U someuser 1223 apache samp02Xsvr -U anotheruser Basically ps aux should list the command that was issued to start the process and if the user name is a flag to the command, then you should be able to find it. Otherwise I really don't know how you expect to tell them apart. Quote Link to comment https://forums.phpfreaks.com/topic/171801-killing-a-process-in-php/#findComment-906377 Share on other sites More sharing options...
ChrisMartino Posted August 26, 2009 Author Share Posted August 26, 2009 i just use / to start the server without the username or the -U Quote Link to comment https://forums.phpfreaks.com/topic/171801-killing-a-process-in-php/#findComment-906550 Share on other sites More sharing options...
trq Posted August 26, 2009 Share Posted August 26, 2009 This is no longer a php question. I would suggest experimenting with the different examples suggested. You should be starting any server processes using your systems init scripts, these usually take care of easily stopping / starting the services. Another thing you can do is as you start the process, write its process id to a file then use that id to kill the process. Again, none if this has anything to do with php. Quote Link to comment https://forums.phpfreaks.com/topic/171801-killing-a-process-in-php/#findComment-906566 Share on other sites More sharing options...
ChrisMartino Posted August 26, 2009 Author Share Posted August 26, 2009 yes it dose i want to do this via php < Quote Link to comment https://forums.phpfreaks.com/topic/171801-killing-a-process-in-php/#findComment-906569 Share on other sites More sharing options...
trq Posted August 26, 2009 Share Posted August 26, 2009 It doesn't. All your doing is calling a shell command via php's exec, its that shell command you need to figure out. No point barking up the wrong tree. Quote Link to comment https://forums.phpfreaks.com/topic/171801-killing-a-process-in-php/#findComment-906571 Share on other sites More sharing options...
roopurt18 Posted August 26, 2009 Share Posted August 26, 2009 You also need to have a way to distinguish the various servers after they have been started. If you have 15 server.exes running, each tied to a different user, and you want to kill one for a specific user and the only information you have is: pid name 12 server.exe 22 server.exe 13 server.exe 44 server.exe 42 server.exe 52 server.exe 62 server.exe 67 server.exe Then how do you expect to accomplish this? You can't without other distinguishing factors. Quote Link to comment https://forums.phpfreaks.com/topic/171801-killing-a-process-in-php/#findComment-906856 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.