How to Check Process Running in Windows Using PHP

Introduction

To Check Process Running in Windows using PHP, we have to use PHP tasklist command with exec() function.

how to check if a windows task is running using PHP

Complete Code to Check Process Running in Windows Using PHP

<?php
// show tasks, redirect errors to NUL (hide errors)
exec("tasklist 2>NUL", $task_list);

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

Code Explanation:

  • On the above code, we use the PHP tasklist command to see what processes are running in Windows.
  • exec is the PHP inbuilt function used to execute an external program and return the last value, if there is no return then it returns the NULL value.
  • In the last line we print the $task_list variable where we store the list of running processes in windows.

Output:

how to check process running in windows

You can check it by running it on you local machine using XAMP or WAMPP.

Also Read: Best PHP IDE Code Editor in 2021 [Updated]

How to Kill Windows Process Using PHP

<?php
exec("taskkill /F /IM taskName.exe 2>NUL");
?>

Code Explanation:

On the above code, we use the same exec() function to execute the PHP tasklist command and by using taskName from the list we can kill the process.

Here is the complete explanation about how we can check process running in windows and also kill by using the command.

To know more you can check PHP: getmypid – Manual.

Also Read:

Happy Coding..!

Was this article helpful?
YesNo
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH, my native place in Odisha. I am a Web Programmer by profession and working on more than 50 projects to date. My passion is working on the web-based project using PHP and relate to all CMS and frameworks which is based on PHP.
Posts created 163

2 thoughts on “How to Check Process Running in Windows Using PHP

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top
mariobet - supertotobet - escort -

takip7.com

We are now accepting Guest Posting and creation of Backlinks
This is default text for notification bar