在以下 C 程序中:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(void){
char *shell = getenv("SHELL");
execl(shell, NULL, NULL);
perror("execl() failed");
}
Run Code Online (Sandbox Code Playgroud)
当我运行上面的代码时,我发现自己在一个新的 shell 中。当我输入exit新的 shell 时,我发现自己又回到了旧的 shell 中。
不应该execl()用一个新的 shell 替换当前的 shell(而不是在旧的 shell 中生成一个新的 shell)?
(Linux 4.16)