When running the following command
strace -f python3 -c 'import os; print(os.getpid())'
I noticed that strace does not catch the call to the getpid(2) system call. I first considered that this was due to glibc caching the pid, but there shouldn't be a pid for libc to cache without at least a single real system call. Then I considered that maybe vdso was the culprit, but running a C program that makes this system call through libc shows a getpid call when straced. I finally gave up and looked up the source of the os.getpid python module, which apparently seems to be defined in Modules/posixmodule.c. To my surprise (and subsequent confusion), it makes a normal call to getpid!
So my question is: How does python determine the result of os.getpid? and if such value is indeed obtained by a call to getpid, how is that call actually being made?
strace -e trace=getpid -f python3 -c 'import os; print(os.getpid())'showed two calls to the getpid syscall when I tested it. - Shawntrace=getpidon two separate systems (both the same version of ubuntu, 16.04, unfortunately). Both print the PID but show no call togetpid; only '+++ exited with 0 +++'. - Tenders McChiken