Opened 10 years ago
Closed 3 years ago
#11797 closed bug (fixed)
Calling getpid() from constructor of global static object returns 0
Reported by: | tokoe | Owned by: | nobody |
---|---|---|---|
Priority: | normal | Milestone: | R1/beta4 |
Component: | System/POSIX | Version: | R1/Development |
Keywords: | Cc: | ||
Blocked By: | Blocking: | #17723 | |
Platform: | x86 |
Description
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)
Change History (7)
by , 10 years ago
comment:1 by , 10 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:2 by , 10 years ago
Implemented by Axel in 2003 btw: http://cgit.haiku-os.org/haiku/commit/src/kernel/libroot/posix/unistd/process.c?id=28d9e59387c3c9dbdc6e569d04c53c39895e9e15
comment:3 by , 10 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?
comment:4 by , 3 years ago
Blocking: | 17723 added |
---|
comment:6 by , 3 years ago
Milestone: | R1 → R1/beta4 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Patch applied in hrev56203.
test case that demonstrate the problem