std::cout << "my pid is " << getpid() << "\n"
long getpid(void)
returns the calling processes id.
getpid()
is implemented as
asmlinkage long sys_getpid(void) return current->tgid
current
is a pointer to the running process's descriptor.
tgid
is the process-descriptor field containing the process id.
typedef struct Pd long tpid Pd pd Pd * current = &pd int fake_getpid() return current->tpid
sw.start() for (unsigned i = 0; i < iters; i++) { } sw.stop() const unsigned overhead = sw.elapsed() sw.start() for (unsigned i = 0; i < iters; i++) getpid() or fake_getpid() sw.stop()
(sw.elapsed() - overhead)/iters
See the code.
iters
= 10,000.
Solaris | Linux | |
---|---|---|
getpid() | 1.54 | 0.45 |
fake_getpid() | 0.04 | 0.01 |
This page last modified on 14 November 2004.