Jump to content

Killing a process in PHP


ChrisMartino

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.