Is it normal that bash stat() and access() much, before commands?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite
1












Running strace on the bash shell that is instructed to run mkdir provided this output which shows lots of stats prior to execve the actual mkdir binary:



 2766 [pid 17371] stat(".", 0750, st_size=17262, ...) = 0
2767 [pid 17371] stat("/usr/local/sbin/mkdir", 0x7ffd87aad0a0) = -1 ENOENT 2767 (No such file or directory)
2768 [pid 17371] stat("/usr/local/bin/mkdir", 0x7ffd87aad0a0) = -1 ENOENT (No such file or directory)
2769 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
2770 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
2771 [pid 17371] access("/usr/bin/mkdir", X_OK) = 0
2772 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
2773 [pid 17371] access("/usr/bin/mkdir", R_OK) = 0
2774 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
2775 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
2776 [pid 17371] access("/usr/bin/mkdir", X_OK) = 0
2777 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
2778 [pid 17371] access("/usr/bin/mkdir", R_OK) = 0
2779 [pid 17371] execve("/usr/bin/mkdir", ["mkdir", "/tmp"], 0x557ec7e15920 /* 5 vars */) = 0


My question is: Is it normal (and if so for what reason) is /usr/bin/mkdir stat()ed a lot?
The output lines are numbered and in particular I wonder what sense will line 2776 make once 2771 was run already. Also I was under the impression bash could have saved all systemcalls from 2770 onward to the final execve as the stat should have provided the information at once? What am I missing?



I have since sought an explanation and checked how an alternative shell the dash shell would behave it also shows some stat()ing :



 2792 [pid 17372] stat("/usr/local/sbin/mkdir", 0x7ffc66010b50) = -1 ENOENT (No such file or directory)
2793 [pid 17372] stat("/usr/local/bin/mkdir", 0x7ffc66010b50) = -1 ENOENT (No such file or directory)
2794 [pid 17372] stat("/usr/sbin/mkdir", 0755, st_size=51136, ...) = 0
2795 [pid 17372] execve("/usr/sbin/mkdir", ["mkdir", "/run"], 0x55d8d3453bb8 /* 6 vars */) = 0


I am aware that the lines 2792,2793, similar to the lines 2767, 2768are because of searching the executable in the various directories in the currentPATH`.



If this is discounted then dash only does one single stat and bash does 10. Again raising the question: is this normal?









share

























    up vote
    0
    down vote

    favorite
    1












    Running strace on the bash shell that is instructed to run mkdir provided this output which shows lots of stats prior to execve the actual mkdir binary:



     2766 [pid 17371] stat(".", 0750, st_size=17262, ...) = 0
    2767 [pid 17371] stat("/usr/local/sbin/mkdir", 0x7ffd87aad0a0) = -1 ENOENT 2767 (No such file or directory)
    2768 [pid 17371] stat("/usr/local/bin/mkdir", 0x7ffd87aad0a0) = -1 ENOENT (No such file or directory)
    2769 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
    2770 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
    2771 [pid 17371] access("/usr/bin/mkdir", X_OK) = 0
    2772 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
    2773 [pid 17371] access("/usr/bin/mkdir", R_OK) = 0
    2774 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
    2775 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
    2776 [pid 17371] access("/usr/bin/mkdir", X_OK) = 0
    2777 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
    2778 [pid 17371] access("/usr/bin/mkdir", R_OK) = 0
    2779 [pid 17371] execve("/usr/bin/mkdir", ["mkdir", "/tmp"], 0x557ec7e15920 /* 5 vars */) = 0


    My question is: Is it normal (and if so for what reason) is /usr/bin/mkdir stat()ed a lot?
    The output lines are numbered and in particular I wonder what sense will line 2776 make once 2771 was run already. Also I was under the impression bash could have saved all systemcalls from 2770 onward to the final execve as the stat should have provided the information at once? What am I missing?



    I have since sought an explanation and checked how an alternative shell the dash shell would behave it also shows some stat()ing :



     2792 [pid 17372] stat("/usr/local/sbin/mkdir", 0x7ffc66010b50) = -1 ENOENT (No such file or directory)
    2793 [pid 17372] stat("/usr/local/bin/mkdir", 0x7ffc66010b50) = -1 ENOENT (No such file or directory)
    2794 [pid 17372] stat("/usr/sbin/mkdir", 0755, st_size=51136, ...) = 0
    2795 [pid 17372] execve("/usr/sbin/mkdir", ["mkdir", "/run"], 0x55d8d3453bb8 /* 6 vars */) = 0


    I am aware that the lines 2792,2793, similar to the lines 2767, 2768are because of searching the executable in the various directories in the currentPATH`.



    If this is discounted then dash only does one single stat and bash does 10. Again raising the question: is this normal?









    share























      up vote
      0
      down vote

      favorite
      1









      up vote
      0
      down vote

      favorite
      1






      1





      Running strace on the bash shell that is instructed to run mkdir provided this output which shows lots of stats prior to execve the actual mkdir binary:



       2766 [pid 17371] stat(".", 0750, st_size=17262, ...) = 0
      2767 [pid 17371] stat("/usr/local/sbin/mkdir", 0x7ffd87aad0a0) = -1 ENOENT 2767 (No such file or directory)
      2768 [pid 17371] stat("/usr/local/bin/mkdir", 0x7ffd87aad0a0) = -1 ENOENT (No such file or directory)
      2769 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
      2770 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
      2771 [pid 17371] access("/usr/bin/mkdir", X_OK) = 0
      2772 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
      2773 [pid 17371] access("/usr/bin/mkdir", R_OK) = 0
      2774 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
      2775 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
      2776 [pid 17371] access("/usr/bin/mkdir", X_OK) = 0
      2777 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
      2778 [pid 17371] access("/usr/bin/mkdir", R_OK) = 0
      2779 [pid 17371] execve("/usr/bin/mkdir", ["mkdir", "/tmp"], 0x557ec7e15920 /* 5 vars */) = 0


      My question is: Is it normal (and if so for what reason) is /usr/bin/mkdir stat()ed a lot?
      The output lines are numbered and in particular I wonder what sense will line 2776 make once 2771 was run already. Also I was under the impression bash could have saved all systemcalls from 2770 onward to the final execve as the stat should have provided the information at once? What am I missing?



      I have since sought an explanation and checked how an alternative shell the dash shell would behave it also shows some stat()ing :



       2792 [pid 17372] stat("/usr/local/sbin/mkdir", 0x7ffc66010b50) = -1 ENOENT (No such file or directory)
      2793 [pid 17372] stat("/usr/local/bin/mkdir", 0x7ffc66010b50) = -1 ENOENT (No such file or directory)
      2794 [pid 17372] stat("/usr/sbin/mkdir", 0755, st_size=51136, ...) = 0
      2795 [pid 17372] execve("/usr/sbin/mkdir", ["mkdir", "/run"], 0x55d8d3453bb8 /* 6 vars */) = 0


      I am aware that the lines 2792,2793, similar to the lines 2767, 2768are because of searching the executable in the various directories in the currentPATH`.



      If this is discounted then dash only does one single stat and bash does 10. Again raising the question: is this normal?









      share













      Running strace on the bash shell that is instructed to run mkdir provided this output which shows lots of stats prior to execve the actual mkdir binary:



       2766 [pid 17371] stat(".", 0750, st_size=17262, ...) = 0
      2767 [pid 17371] stat("/usr/local/sbin/mkdir", 0x7ffd87aad0a0) = -1 ENOENT 2767 (No such file or directory)
      2768 [pid 17371] stat("/usr/local/bin/mkdir", 0x7ffd87aad0a0) = -1 ENOENT (No such file or directory)
      2769 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
      2770 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
      2771 [pid 17371] access("/usr/bin/mkdir", X_OK) = 0
      2772 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
      2773 [pid 17371] access("/usr/bin/mkdir", R_OK) = 0
      2774 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
      2775 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
      2776 [pid 17371] access("/usr/bin/mkdir", X_OK) = 0
      2777 [pid 17371] stat("/usr/bin/mkdir", 0755, st_size=51136, ...) = 0
      2778 [pid 17371] access("/usr/bin/mkdir", R_OK) = 0
      2779 [pid 17371] execve("/usr/bin/mkdir", ["mkdir", "/tmp"], 0x557ec7e15920 /* 5 vars */) = 0


      My question is: Is it normal (and if so for what reason) is /usr/bin/mkdir stat()ed a lot?
      The output lines are numbered and in particular I wonder what sense will line 2776 make once 2771 was run already. Also I was under the impression bash could have saved all systemcalls from 2770 onward to the final execve as the stat should have provided the information at once? What am I missing?



      I have since sought an explanation and checked how an alternative shell the dash shell would behave it also shows some stat()ing :



       2792 [pid 17372] stat("/usr/local/sbin/mkdir", 0x7ffc66010b50) = -1 ENOENT (No such file or directory)
      2793 [pid 17372] stat("/usr/local/bin/mkdir", 0x7ffc66010b50) = -1 ENOENT (No such file or directory)
      2794 [pid 17372] stat("/usr/sbin/mkdir", 0755, st_size=51136, ...) = 0
      2795 [pid 17372] execve("/usr/sbin/mkdir", ["mkdir", "/run"], 0x55d8d3453bb8 /* 6 vars */) = 0


      I am aware that the lines 2792,2793, similar to the lines 2767, 2768are because of searching the executable in the various directories in the currentPATH`.



      If this is discounted then dash only does one single stat and bash does 10. Again raising the question: is this normal?







      bash stat dash syscalls





      share












      share










      share



      share










      asked 5 mins ago









      humanityANDpeace

      4,67743451




      4,67743451

























          active

          oldest

          votes











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475877%2fis-it-normal-that-bash-stat-and-access-much-before-commands%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475877%2fis-it-normal-that-bash-stat-and-access-much-before-commands%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)