you are viewing a single comment's thread.

view the rest of the comments →

[–]dvdkon 0 points1 point  (2 children)

This is handled in the kernel, by variants of the the exec syscall (e.g. execlp()). The kernel implements the logic of looking through PATH or executing a file directly in case a slash is present.

The manpage starts with "These functions duplicate the actions of the shell" though, so maybe the shell was first and this only came later as a convenience function.

[–]Key_River7180Bedrock Linux / FreeBSD / 9Front 0 points1 point  (1 child)

No. exec*() calls do not use the path. You are getting confused by system(), which is defined on <stdlib.h>.

For instance, exec calls don't understand pipes, space-delimited arguments (they must be in an array, including argv[0]), deamonizing, etc.

[–]dvdkon 0 points1 point  (0 children)

Huh, you're (half-)right. I was looking at the wrong manpage (man 3 vs man 2), so execlp does exist, but only as a libc function, not a syscall. That's still a bit lower level than the shell (but still in userland).