Linux API 中的哪个函数使用 shebang 执行脚本文件?

what function in Linux API implements execution of a script file with a shebang?

来自https://unix.stackexchange.com/a/2910/674

... the way shebang (#!) is typically implemented:

  1. The kernel opens the executable, and finds that it starts with #!.
  2. The kernel closes the executable and opens the interpreter instead.
  3. The kernel inserts the path to the script to the argument list (as argv[1]), and executes the interpreter.

我想知道 Linux API 中的哪个函数实现了上述步骤以使用 shebang 执行脚本文件?

我考虑了以下可能性,但 none 似乎匹配:

谢谢。

应该由execve()实施。 exec 家族中的所有其他函数都只是围绕它的包装(以 p 结尾的函数执行 $PATH 搜索以查找可执行参数,以 l 结尾的函数构建argv 数组通过遍历可变参数列表)。

它对任何语言的解释器都是一样的——该机制并不真正关心 shebang 行中的程序做什么,它只是使用脚本路径名作为参数来执行它。你甚至可以这样做:

#!/bin/cat

创建一个在您执行时只打印自身的文件。