MOCKSTACKS
EN
Questions And Answers

More Tutorials




How to get list of all processes running in PHP?


Example 1


$execstring='ps -f -u www-data 2>&1';
$output="";
exec($execstring, $output);
print_r($output);

Output

Array (
[0] => UID PID PPID C STIME TTY TIME CMD
[1] => www-data 1587 790 0 14:04 ? 00:00:00 /usr/sbin/apache2 -k start
[2] => www-data 7336 790 0 17:45 ? 00:00:00 /usr/sbin/apache2 -k start
[3] => www-data 13426 16637 0 20:41 ? 00:00:00 sh -c ps -f -u www-data 2>&1
[4] => www-data 13427 13426 0 20:41 ? 00:00:00 ps -f -u www-data
[5] => www-data 13428 22299 0 20:41 ? 00:00:00 sh -c ps -f -u www-data 2>&1
[6] => www-data 16412 790 0 15:19 ? 00:00:00 /usr/sbin/apache2 -k start
[7] => www-data 16637 790 0 15:19 ? 00:00:00 /usr/sbin/apache2 -k start
[8] => www-data 18977 790 0 06:25 ? 00:00:00 /usr/sbin/apache2 -k start
[9] => www-data 18978 790 0 06:25 ? 00:00:00 /usr/sbin/apache2 -k start
[10] => www-data 18979 790 0 06:25 ? 00:00:00 /usr/sbin/apache2 -k start
[11] => www-data 18981 790 0 06:25 ? 00:00:00 /usr/sbin/apache2 -k start
[12] => www-data 18983 790 0 06:25 ? 00:00:00 /usr/sbin/apache2 -k start
[13] => www-data 19735 1 0 15:39 ? 00:00:00 php sql_runner.php
[14] => www-data 22299 1 13 Mar23 ? 1-02:30:32 php scheduler.php
[15] => www-data 22768 790 0 06:38 ? 00:00:00 /usr/sbin/apache2 -k start )

Example 2


exec("tasklist 2>NUL", $task_list);

echo "<pre>"; print_r($task_list);


Conclusion

In this page (written and validated by ) you learned about . What's Next? If you are interested in completing PHP tutorial, we encourage you simply to start here: PHP Tutorial.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.