为什么以不同的用户身份运行命令时性能急剧下降

Bhu*_*van 1 c linux bash redhat su

我有一个问候世界的C例子./a.out

现在我使用time以下命令测量执行时间

time  ./a.out
Hello World
real    0m0.001s
user    0m0.000s
sys     0m0.002s

time runuser -l root -c './a.out'
real    0m0.017s
user    0m0.004s
sys     0m0.011s

time su -s /bin/bash -c "./a.out" root 
Hello World
real    0m0.080s ---> 80 times slower
user    0m0.005s
sys     0m0.071s
Run Code Online (Sandbox Code Playgroud)

为什么第三个命令80时间比第一个命令慢?

环境 - Redhat 7

yol*_*yer 8

使用第二个和第三个命令,该time命令也会启动runuser,su并且bash还需要一些时间.

如果你这样做,它不应该有太多的区别:

$ runuser -l root -c 'time ./a.out'
Run Code Online (Sandbox Code Playgroud)

和:

$ su -s /bin/bash -c "time ./a.out" root
Run Code Online (Sandbox Code Playgroud)