Opened 5 years ago

Last modified 5 years ago

#11797 new bug

Calling getpid() from constructor of global static object returns 0

Reported by: tokoe Owned by: nobody
Priority: normal Milestone: R1
Component: System/POSIX Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Platform: x86


If you call getpid() from within the constructor of a custom class and create a global static object of that class, getpid() returns 0 instead of the process ID. Calling getpid() from inside main() function or any scope that is entered later on, works fine.

Attachments (1)

main.cpp (289 bytes ) - added by tokoe 5 years ago.
test case that demonstrate the problem

Download all attachments as: .zip

Change History (4)

by tokoe, 5 years ago

Attachment: main.cpp added

test case that demonstrate the problem

comment:1 by korli, 5 years ago

This ID is local and initialized by the function calling the main(), after global constructors. Caching this ID is probably a "bad idea" anyway.

comment:3 by tokoe, 5 years ago

So is there a chance to fix that behavior (because on other Unix/POSIX systems like Linux, FreeBSD or MacOSX it works), or are there any technical limitations in the process handling/C runtime of Haiku?

Note: See TracTickets for help on using tickets.