skip to Main Content

I want to get list of running processes for current user to assure if “file.php” is still running or not?
I’m using cPanel and web server is Litespeed.

4

Answers


  1. Here is what you need:

    1. prepare the OS customized query to list running processes, on linux for example ps faux | grep -i file.php
    2. execute PHP command exec or similar
    3. parse returned values if needed to find the file running aka file.php
    Login or Signup to reply.
  2. First of You need to Just write top in command prompt.Then you can see all the list of service running as of now.

    Go to you php code and use exec function to run this command.

    Login or Signup to reply.
  3. show tasks, redirect errors to NUL (hide errors)

    exec("tasklist 2>NUL", $task_list);
    
    echo "<pre>"; print_r($task_list);
    
    Login or Signup to reply.
  4. $execstring='ps -f -u www-data 2>&1';
    $output="";
    exec($execstring, $output);
    print_r($output);
    

    Will give you something like this

    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 )
    

    No you can filter/search with regex for your file.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search