Hacker News new | ask | show | jobs
by Animats 412 days ago
> The thing is, though, that PATH being a userspace concept is a contingent detail, an accident of history, not something inherent to the concept of an operating system. You can imagine a kernel that does path searches. Why not?

Right. You can't be sure that someone didn't stick $PATH expansion into glibc, or something. Because someone did.

QNX gets program loading entirely out of the kernel. When QNX is booted, initial programs and .so files in the boot image are loaded into memory. That's how things get started. Disk drivers, etc. come in that way, assuming the system has a disk.

Calling "exec.." or ".. spawn" merely links to a .so file that knows how to open and read an executable image. Program loading is done entirely by userspace code. Tiny microkernel. The "exec.." functions do not use the PATH variable.[1]

However, "posix_spawn" does read the PATH environment variable, in both QNX [2] and Linux.[3] Linux, for historical reasons, tends not to use "spawn" as much, but those are the defined semantics for it. QNX normally uses "spawn", because it lacks the legacy that encouraged fork/exec type process startup. "posix_spawn" is apparently faster in modern Linux, especially when the parent process is large, but there's a lot of fork/exec legacy code out there.

"posix_spawn" comes from FreeBSD in 2009, but I think the QNX implementation precedes that, because QNX's architecture favors "spawn" over "exec.." It may go back to UCLA Locus.

Windows has different program startup semantics. Someone from Windows land can address that. MacOS has a built in search path if you don't have a PATH variable.[5]

[1] https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino...

[2] https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino...

[3] https://www.man7.org/linux/man-pages/man3/posix_spawn.3.html

[4] https://www.whexy.com/posts/fork

[5] https://developer.apple.com/library/archive/documentation/Sy...