On 2 Apr 2013, at 15:11, Sorin Badea <sorin.bade...@gmail.com> wrote:

> I'm trying to implement a standalone threading component, and in current 
> implementation I'm using `popen` to run a separate process with some 
> arguments that I'm using to identify them (for example `php 
> some_dummy_file.php -thread_id=<some_hash>`). This way when I'm trying to see 
> which are my threads I don't have to check every stored pid and see if they 
> are still up. 

Personally I would be storing the PIDs somewhere, but that's just me.

The other way you could probably do it is by having the main script (the one 
executed on the command line) named something unique, the use dirname(__FILE__) 
to get that name from within that script. Then parse the PS output for that 
script name. You may need to exclude lines containing bash or similar depending 
on how the script was executed.

Seriously, PIDs are the way to go! Based on what you've put above you already 
have some sort of storage that's tracking threads (they have a hash), so why 
not add the PID to that? Or, even better, use the PID as that hash?

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/


> On Tue, Apr 2, 2013 at 5:02 PM, Stuart Dallas <stu...@3ft9.com> wrote:
> On 2 Apr 2013, at 14:50, Sorin Badea <sorin.bade...@gmail.com> wrote:
> 
>> I don't want to wait for it and surely I don't want to safe that pid in
>> same place. I just want to use `ps` with a pattern to return my forked
>> process.
> 
> Storing the PID of a process you need to monitor is the established method, 
> and is certainly the most reliable. Why can't you use the PID as the pattern 
> to look for? If there's a reason then please explain it as that will help us 
> assist you. If there's no reason then I don't understand why you're trying to 
> over-complicate it.
> 
> If you're just wanting to monitor it from the process that forked it then you 
> don't need to store the PID anywhere other than a variable, and you don't 
> need to wait for it.
> 
> If you absolutely must do this then the only way is via an extension such as 
> proctitle: http://php.net/setproctitle
> 
> -Stuart
> 
> -- 
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/
> 
>> On Tue, Apr 2, 2013 at 4:48 PM, Matijn Woudt <tijn...@gmail.com> wrote:
>> 
>>> Hi,
>>> 
>>> pcntl_fork will return the pid of the fork, what is wrong with using that
>>> pid to identify the process?
>>> 
>>> - Matijn
>>> 
>>> 
>>> On Tue, Apr 2, 2013 at 3:38 PM, Sorin Badea <sorin.bade...@gmail.com>wrote:
>>> 
>>>> Hi guys,
>>>> I'm trying to find a solution to identify a php process that is spawned
>>>> with pnctl_fork. I've tried to set a custom gid but this isn't viable
>>>> because I have to run the parent proc with administrative permissions. I
>>>> need to do this native without any pecl extensions.
>>>> Is there a way to do this ?
>>>> 
>>>> Regards,
>>>> --
>>>> Badea Sorin (unu.sorin)
>>>> sorin.bade...@gmail.com
>>>> unu_so...@yahoo.com
>>>> 
>>> 
>>> 
>> 
>> 
>> -- 
>> Badea Sorin (unu.sorin)
>> sorin.bade...@gmail.com
>> unu_so...@yahoo.com
>> Pagina personala:
>> http://badeasorin.com
> 
> 
> 
> 
> -- 
> Badea Sorin (unu.sorin)
> sorin.bade...@gmail.com
> unu_so...@yahoo.com
> Pagina personala:
> http://badeasorin.com

Reply via email to