You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Damir Dezeljin <pr...@mbss.org> on 2003/02/18 10:13:32 UTC

How to get the PID?

Hi.

Is there a way to get a PID of the current process? I checked the docs,
however I didn't find a function that fit my needs (hehe ... maybe I
missed something ;) ).

I need the PID to implement an logging for my progy.

Regards,
Dezo


Re: How to get the PID?

Posted by Branko Čibej <br...@xbc.nu>.
Cliff Woolley wrote:

>On Tue, 18 Feb 2003, [UTF-8] Branko Čibej wrote:
>
>  
>
>>It's fairly portable on most every Unix variant. It just so happens that
>>APR isn't about portability across Unixes, so we really should have
>>wrappers. We have apr_os_thread_current, so we should also have an
>>apr_os_proc_current.
>>    
>>
>
>Of course we all realize that not all operating systems *have* processes
>(cough Netware cough :).  Not that that has to be a problem...
>apr_os_proc_current() could just return a constant in that case.  Just
>bringing it up.  +1 on concept.
>  
>
Well, Netware does define apr_os_proc_t, so presumably it has other
magic to make it work.

What worries me is that we don't seem to have an apr_os_proc_get,
either. Is that just another ommossion, or was it deliberate?

-- 
Brane Čibej   <br...@xbc.nu>   http://www.xbc.nu/brane/


Re: How to get the PID?

Posted by Cliff Woolley <jw...@virginia.edu>.
On Tue, 18 Feb 2003, [UTF-8] Branko Čibej wrote:

> It's fairly portable on most every Unix variant. It just so happens that
> APR isn't about portability across Unixes, so we really should have
> wrappers. We have apr_os_thread_current, so we should also have an
> apr_os_proc_current.

Of course we all realize that not all operating systems *have* processes
(cough Netware cough :).  Not that that has to be a problem...
apr_os_proc_current() could just return a constant in that case.  Just
bringing it up.  +1 on concept.

--Cliff


Re: How to get the PID?

Posted by Branko Čibej <br...@xbc.nu>.
Justin Erenkrantz wrote:

> --On Tuesday, February 18, 2003 10:13 AM +0100 Damir Dezeljin
> <pr...@mbss.org> wrote:
>
>> Is there a way to get a PID of the current process? I checked the
>> docs, however I didn't find a function that fit my needs (hehe ...
>> maybe I missed something ;) ).
>
>
> You can call getpid().  I believe that's fairly portable.  You can do:
>
> apr_os_proc_t pid = getpid();
>
> If getpid() isn't really portable, we could add wrappers.  Patches
> welcomed.  -- justin


It's fairly portable on most every Unix variant. It just so happens that
APR isn't about portability across Unixes, so we really should have
wrappers. We have apr_os_thread_current, so we should also have an
apr_os_proc_current.

The interesting thing is that an apr_os_proc_t is _not_ a good unique id
for, e.g., logging. On Windows, that's a process HANDLE (the value is
process-specific) , not a process ID which _is_ unique on the system. So
to be completely safe, we'd also need a way to get the PID from an
apr_os_{proc,thread}_t.

Here's what I suggest we add to apr_protable.h:

    typedef <system-specific> apr_os_proc_id_t;
    typedef <system-specific> apr_os_thread_id_t;

    APR_DECLARE(apr_os_proc_t) apr_os:_proc_current(void);

    APR_DECLARE(apr_status_t) apr_os_proc_id(apr_os_proc_id_t*,
apr_os_proc_t);
    APR_DECLARE(apr_status_t) apr_os_thread_id(apr_os_thread_id_t*,
apr_os_thread_t);

I expect we'd also need

    #define APR_OS_PROC_ID_FMT
    #define APR_OS_THREAD_ID_FMT

for printing those values.

-- 
Brane Čibej   <br...@xbc.nu>   http://www.xbc.nu/brane/


Re: How to get the PID?

Posted by Justin Erenkrantz <ju...@erenkrantz.com>.
--On Tuesday, February 18, 2003 10:13 AM +0100 Damir Dezeljin 
<pr...@mbss.org> wrote:

> Is there a way to get a PID of the current process? I checked the
> docs, however I didn't find a function that fit my needs (hehe ...
> maybe I missed something ;) ).

You can call getpid().  I believe that's fairly portable.  You can do:

apr_os_proc_t pid = getpid();

If getpid() isn't really portable, we could add wrappers.  Patches 
welcomed.  -- justin

Re: How to get the PID?

Posted by Branko Čibej <br...@xbc.nu>.
Branko Čibej wrote:

>Hmm, looking at our apr_proc_t, I see we _also_ use plain pid_t in there
>(and define it in apr.h on platforms that don't have it). This explains
>why we don't have an apr_os_proc_get -- users will simple use the pid
>member from apr_proc_t. But we don't have one of those
>
Eeek. By "one of those" I meant an apr_os_proc_t, of course, not a
pid_t. What I meant to say was: that without and apr_os_proc_t member,
apr_proc_t is funcamentally broken. There, that's clearer, I hope.

> in apr_proc_t at
>all, which seems just a bit strange to me, and upon reflection I think
>that apr_proc_t is fundamentally broken because of that. It might be a
>bit hard to unbreak it while still maintaining backward compatibility,
>though...
>
>  
>


-- 
Brane Čibej   <br...@xbc.nu>   http://www.xbc.nu/brane/


Re: How to get the PID?

Posted by Branko Čibej <br...@xbc.nu>.
Hmm, looking at our apr_proc_t, I see we _also_ use plain pid_t in there
(and define it in apr.h on platforms that don't have it). This explains
why we don't have an apr_os_proc_get -- users will simple use the pid
member from apr_proc_t. But we don't have one of those in apr_proc_t at
all, which seems just a bit strange to me, and upon reflection I think
that apr_proc_t is fundamentally broken because of that. It might be a
bit hard to unbreak it while still maintaining backward compatibility,
though...

-- 
Brane Čibej   <br...@xbc.nu>   http://www.xbc.nu/brane/