I am using macOS with SIP enabled. And I am figuring out why the scripts run so slowly with the SIP after a modification or creation.
And I found if I modify a script by editors like vim or nano, and run it by ./script.bash, it will take about 1 second to finish the script for the first time after each modification.
For example. If the script.bash is:
#!/bin/bash echo 1 And I change it to below by vim. It takes me about ten times longer time to run it.
#!/bin/bash echo 1 echo 2 bash-3.2$ time ./script.bash # First time after modification by vim 1 2 real 0m0.884s user 0m0.001s sys 0m0.002s bash-3.2$ time ./script.bash # Second time after modification by vim 1 2 real 0m0.003s user 0m0.001s sys 0m0.002s While if I currently append the file by some command's output redirection like echo "echo 3" >> script.bash and still call the script by ./script.bash, the delay is gone.
bash-3.2$ echo "echo 3" >> script.bash bash-3.2$ time ./script.bash # First time after modification by echo 1 2 3 real 0m0.004s user 0m0.001s sys 0m0.002s bash-3.2$ time ./script.bash # Second time after modification by echo 1 2 3 real 0m0.002s user 0m0.001s sys 0m0.001s So what's the difference between the two ways of writing a file? And why the delay happens only with SIP enabled?
exec(), becausebash ./script.bashexecutes the script smoothly. But it is really annoying when I am practising scripting, almost every modification cause a more second delay to finish. And compared to reason the why it delays, I am more curious at why the second way makes no delays. Because I think the only choice to solve the problem is disable SIP,lol.