Reputation: 1209
This is actually a 2 part question.
posix_spawn()
faster than hand written fork()
+ exec()
when posix_spawn()
is itself just a wrapper around fork()
+ exec()
?posix_spawn()
with POSIX_SPAWN_USEVFORK
slower than normal hand written vfork()
+ exec()
?According to Ruby posix spawning library work it seems like posix_spawn()
is giving consistent throughput. I read the source code of glibc, but I couldn't find anything obvious that is giving this consistency. Can someone explain it to me?
I made a small test source file (too big for here, so GitHub), and had it run about 30 times - each time invoking /bin/true
several times (random number between 1000-10000) - then dividing the total time consumed by total iterations. The results are shown below. Its run on an average Linux Mint desktop with no bells and whistles attached.
I gather the man page considers vfork()
to be an architectural blemish, but for my use cases, its just fine.
Here, the v
prefix is using vfork()
and n
prefix is the normal fork()
.
Upvotes: 1
Views: 1886