1

My problem is that I have a command running in the shell and I want to stop it from PHP (using shell_exec ). I found this

pkill [name of command]

and it works fine when the command is composed of one word.

shell_exec('pkill ping');

but my command is 'npm run test bla bla bla ' I tried also to get the pid of my running process using

pgrep [name of command]

and then use kill -9 but this doesn't work because I have also a command with more than 1 word. Thank you

Harsha pps
  • 2,012
  • 2
  • 25
  • 35
kmar akrout
  • 355
  • 1
  • 6
  • 16
  • Wait, your problem is that "is composed by several words", or maybe, that you started a node.js service? First: If you want to test commands, do NOT test it over PHP, but do it directly in the Linux terminal. Second: To stop `npm`-related processes and services you should check out the official Node.js documentation. – David Tabernero M. Aug 14 '18 at 17:42
  • 1
    Possible duplicate of [Find and kill a process in one line using bash and regex](https://stackoverflow.com/q/3510673/608639), [How to get the pid of a running process using a single command that parse the output of ps?](https://superuser.com/q/481408/173513), [Shell script to capture Process ID and kill it if exist](https://stackoverflow.com/q/13910087/608639), [How to get the process ID to kill a nohup process?](https://stackoverflow.com/q/17385794/608639), etc. – jww Aug 15 '18 at 01:40

0 Answers0