Justin Erenkrantz wrote:

> --On Tuesday, February 18, 2003 10:13 AM +0100 Damir Dezeljin
> <[EMAIL PROTECTED]> 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   <[EMAIL PROTECTED]>   http://www.xbc.nu/brane/

Reply via email to