The Function POSIX_Kill() in PHP
The POSIX extension provides a number of functions that enable you to retrieve information about the effective and real user IDs of a process (this article will focus on the user-related ones). It also gives you the ability to send signals to processes (although you should be aware that the signals are not sent in the same order as they appear in the system, so SIGTERM may not always be received by the program you're killing if you use this technique; this depends on which platform you are using PHP on).
The function posix_kill() is part of the POSIX library that enables you to manage processes within your PHP script. It's crucial for allowing you to control the execution flow of your code and, as such, it's worth familiarizing yourself with it.
As far as signals are concerned, I should point out that if you kill a process with this function, it will send signal number 15 (SIGTERM) to the process; the purpose of this is to give the program a chance to clean up its environment before exiting. For this reason, it is generally considered a bad idea to simply execute external programs from within PHP without using this function or the equivalents (like shell_exec(), passthru(), exec() or popen()).
There's no way to guarantee that an external program will use the same escape characters that you use in your script. This can lead to problems, especially when you execute commands from the CLI, where it's possible for malicious hackers to harvest data, such as usernames and passwords, from the list of programs running on the system (which you can see by using the ps command). To avoid this, it's generally best to use the functions escapeshellarg() and escapeshellcmd().