7 ms·
The funny thing is its not transitive. No slowdown if you invoke bash specifically with a new shell. % rm /tmp/test.sh ; echo $'#!/bin/sh\necho Hello' > /tmp/
by jwlake 6y ago
The funny thing is its not transitive. No slowdown if you invoke bash specifically with a new shell.
% rm /tmp/test.sh ; echo $'#!/bin/sh\necho Hello' > /tmp/test.sh && chmod a+x /tmp/test.sh
% time bash /tmp/test.sh && time bash /tmp/test.sh
Hello
bash /tmp/test.sh 0.00s user 0.00s system 83% cpu 0.004 total
Hello
bash /tmp/test.sh 0.00s user 0.00s system 77% cpu 0.003 total
vs the one from the article:
% rm /tmp/test.sh ; echo $'#!/bin/sh\necho Hello' > /tmp/test.sh && chmod a+x /tmp/test.sh
% time /tmp/test.sh && time /tmp/test.sh
Hello
/tmp/test.sh 0.00s user 0.00s system 2% cpu 0.134 total
Hello
/tmp/test.sh 0.00s user 0.00s system 73% cpu 0.004 total
(edited for formating)
- deleted 6y ago[deleted]
- azinman2 6y agoAre you sure it's just not cached from the prior result? If I run the article's commands twice in a row, the 2nd time is faster.
- saurik 6y agoWhen you run "bash hello" you are calling exec() on bash, passing "hello" as an argument, which bash then reads; when you run "./hello" you are calling exec() on hello: the kernel then treats "hello" as an executable, but notes that "hello" starts with "#!" and then will run the specified interpreter for you, passing "./hello" as an argument. The kernel doesn't think of "hello" as a program when you run "bash hello".