By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,665 Members | 1,251 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,665 IT Pros & Developers. It's quick & easy.

getting process id in php

shoonya
100+
P: 161
i am using windows XP

and using
popen("start notepad","r");

to start a note pad
now how can i get the process id of this notepad

shoonya
Jun 18 '07 #1
Share this Question
Share on Google+
4 Replies


Atli
Expert 5K+
P: 5,058
Check out the proc_get_status() function.
It should get you what you need.
Jun 18 '07 #2

shoonya
100+
P: 161
thanks a lot atil

but when I am using popen to open the note pad it's giving error
[PHP]
PHP Warning: proc_get_status(): supplied resource is not a valid process resource in C:\Program Files\Apache Group\Apache2\htdocs\quedge3\index\test.php on line 46[/PHP]

i think it's looking for a process that has been opened by proc_open but i am not able to get the syntax of proc_open

so help me out
i am stuck here for last 2 days :(

shoonya
Jun 18 '07 #3

Atli
Expert 5K+
P: 5,058
I managed to get this working using the 'ipconfig' command, didn't manage to get a notepad window. Don't really undestand why you'd want that anyways.

But anyhow.. this is my code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. error_reporting(E_ALL);
  3.  
  4. $descriptorspec = array(
  5.    0 => array("pipe", "r"),
  6.    1 => array("pipe", "w"), 
  7.    2 => array("pipe", "r")
  8. );
  9.  
  10. $process = proc_open('ipconfig', $descriptorspec, $pipes);
  11.  
  12. if (is_resource($process)) {
  13.  
  14.     // Get the proccess info
  15.     echo "Proccess information:<pre>";
  16.     $var = proc_get_status($process);
  17.     print_r($var);
  18.     echo "</pre>";
  19.  
  20.     // Print stream from proccess
  21.     echo "Process output:<pre>";
  22.     echo stream_get_contents($pipes[1]);
  23.     echo "</pre>";
  24.     fclose($pipes[1]);
  25.  
  26.     // It is important that you close any pipes before calling
  27.     // proc_close in order to avoid a deadlock
  28.     $return_value = proc_close($process);
  29.  
  30.     // Print return value (0 if success)
  31.     echo "Process returned:<pre>";
  32.     echo $return_value ."\r\n";
  33.     echo "</pre>";
  34. }
  35. else
  36. {
  37.   echo "Process failed to open";
  38. }
  39. ?>
  40.  
This is based on an example found at php.net/proc_open
Jun 19 '07 #4

shoonya
100+
P: 161
ooops
you have just pasted the example from php.net

I was not getting the concept of pipes and streams
so any good tutorial or link will work for me

shoonya
Jun 20 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.