Do the first two arguments in exec* functions contain redundant information?












3















I seem to miss something about those exec* functions.



The first argument is the filename or pathname of the executable to be executed.



The second argument (when l) or the first element of the second argument (when v) is also something similar. For example, here.



Do we really need to repeatedly duplicate redundancy? Thanks.










share|improve this question

























  • I just found unix.stackexchange.com/questions/315812/…

    – Tim
    Nov 28 '18 at 19:49











  • and unix.stackexchange.com/questions/484734/…

    – Tim
    Nov 28 '18 at 20:04
















3















I seem to miss something about those exec* functions.



The first argument is the filename or pathname of the executable to be executed.



The second argument (when l) or the first element of the second argument (when v) is also something similar. For example, here.



Do we really need to repeatedly duplicate redundancy? Thanks.










share|improve this question

























  • I just found unix.stackexchange.com/questions/315812/…

    – Tim
    Nov 28 '18 at 19:49











  • and unix.stackexchange.com/questions/484734/…

    – Tim
    Nov 28 '18 at 20:04














3












3








3








I seem to miss something about those exec* functions.



The first argument is the filename or pathname of the executable to be executed.



The second argument (when l) or the first element of the second argument (when v) is also something similar. For example, here.



Do we really need to repeatedly duplicate redundancy? Thanks.










share|improve this question
















I seem to miss something about those exec* functions.



The first argument is the filename or pathname of the executable to be executed.



The second argument (when l) or the first element of the second argument (when v) is also something similar. For example, here.



Do we really need to repeatedly duplicate redundancy? Thanks.







c linux






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 16:16









dbush

103k13108145




103k13108145










asked Nov 28 '18 at 16:09









TimTim

31.7k109247373




31.7k109247373













  • I just found unix.stackexchange.com/questions/315812/…

    – Tim
    Nov 28 '18 at 19:49











  • and unix.stackexchange.com/questions/484734/…

    – Tim
    Nov 28 '18 at 20:04



















  • I just found unix.stackexchange.com/questions/315812/…

    – Tim
    Nov 28 '18 at 19:49











  • and unix.stackexchange.com/questions/484734/…

    – Tim
    Nov 28 '18 at 20:04

















I just found unix.stackexchange.com/questions/315812/…

– Tim
Nov 28 '18 at 19:49





I just found unix.stackexchange.com/questions/315812/…

– Tim
Nov 28 '18 at 19:49













and unix.stackexchange.com/questions/484734/…

– Tim
Nov 28 '18 at 20:04





and unix.stackexchange.com/questions/484734/…

– Tim
Nov 28 '18 at 20:04












4 Answers
4






active

oldest

votes


















2














They often do have the same information but it’s not redundant. The first is the name of the executable, but the second is what the executable sees as the name. For example, BusyBox uses links to provide different functionality based on the name with which the executable is called. So sometimes you want to give a different name to the called binary than the one on disk.






share|improve this answer
























  • Thanks. could you be specific about "BusyBox uses links to provide different functionality based on the name with which the executable is called"?

    – Tim
    Nov 28 '18 at 16:41











  • @Tim BusyBox is kind of “all shell tools in one binary.” There’s only one executable on disk and tools like ls, cp etc are links to the binary. When it’s run by ls the binary can check from the argument list that it was run as ls and should provide that functionality. When as cp it will function as cp. So regardless of the actual binary file the executed program can have different “name” for how it was being run.

    – Sami Kuhmonen
    Nov 28 '18 at 16:51



















2














By convention, the first argument to a program (i.e. argv[0]) is the name of the program being executed, however it doesn't necessarily have to be.



For example:



execl("/bin/ls", "ls", "-l", (void *)NULL);


In this case, the program to run is the full path to the executable, while the first argument is just the executable name without the path.






share|improve this answer
























  • Thanks. Out of curiosity, is execl() your favourite out of the exec* family, in cases when several of them are applicable?

    – Tim
    Nov 29 '18 at 0:09





















2














You can give anything you want as arg (the second argument).
Even "nothing" (arg = [NULL]).



The only effect it will have is that the program called will have as argv exactly what you give it throught arg.



However, some program expect to always have argv[0] and doesn't check if argv[0] is NULL or not. If you give nothing, you can break the program called.



Other than that, it should not cause any problem has any sane program will check his argument.






share|improve this answer

































    1














    If you feel you won't ever want the first array member to differ from the first argument, you can always wrap the function to avoid the repetion:



    int my_execvp(char const *argv) { return execvp(argv[0],argv); }





    share|improve this answer
























    • Thanks. Is execvp the only one out of the exec* family which you can apply the workaround? ( I guess yes)

      – Tim
      Nov 29 '18 at 0:11













    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53523675%2fdo-the-first-two-arguments-in-exec-functions-contain-redundant-information%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    They often do have the same information but it’s not redundant. The first is the name of the executable, but the second is what the executable sees as the name. For example, BusyBox uses links to provide different functionality based on the name with which the executable is called. So sometimes you want to give a different name to the called binary than the one on disk.






    share|improve this answer
























    • Thanks. could you be specific about "BusyBox uses links to provide different functionality based on the name with which the executable is called"?

      – Tim
      Nov 28 '18 at 16:41











    • @Tim BusyBox is kind of “all shell tools in one binary.” There’s only one executable on disk and tools like ls, cp etc are links to the binary. When it’s run by ls the binary can check from the argument list that it was run as ls and should provide that functionality. When as cp it will function as cp. So regardless of the actual binary file the executed program can have different “name” for how it was being run.

      – Sami Kuhmonen
      Nov 28 '18 at 16:51
















    2














    They often do have the same information but it’s not redundant. The first is the name of the executable, but the second is what the executable sees as the name. For example, BusyBox uses links to provide different functionality based on the name with which the executable is called. So sometimes you want to give a different name to the called binary than the one on disk.






    share|improve this answer
























    • Thanks. could you be specific about "BusyBox uses links to provide different functionality based on the name with which the executable is called"?

      – Tim
      Nov 28 '18 at 16:41











    • @Tim BusyBox is kind of “all shell tools in one binary.” There’s only one executable on disk and tools like ls, cp etc are links to the binary. When it’s run by ls the binary can check from the argument list that it was run as ls and should provide that functionality. When as cp it will function as cp. So regardless of the actual binary file the executed program can have different “name” for how it was being run.

      – Sami Kuhmonen
      Nov 28 '18 at 16:51














    2












    2








    2







    They often do have the same information but it’s not redundant. The first is the name of the executable, but the second is what the executable sees as the name. For example, BusyBox uses links to provide different functionality based on the name with which the executable is called. So sometimes you want to give a different name to the called binary than the one on disk.






    share|improve this answer













    They often do have the same information but it’s not redundant. The first is the name of the executable, but the second is what the executable sees as the name. For example, BusyBox uses links to provide different functionality based on the name with which the executable is called. So sometimes you want to give a different name to the called binary than the one on disk.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 28 '18 at 16:12









    Sami KuhmonenSami Kuhmonen

    21.5k73149




    21.5k73149













    • Thanks. could you be specific about "BusyBox uses links to provide different functionality based on the name with which the executable is called"?

      – Tim
      Nov 28 '18 at 16:41











    • @Tim BusyBox is kind of “all shell tools in one binary.” There’s only one executable on disk and tools like ls, cp etc are links to the binary. When it’s run by ls the binary can check from the argument list that it was run as ls and should provide that functionality. When as cp it will function as cp. So regardless of the actual binary file the executed program can have different “name” for how it was being run.

      – Sami Kuhmonen
      Nov 28 '18 at 16:51



















    • Thanks. could you be specific about "BusyBox uses links to provide different functionality based on the name with which the executable is called"?

      – Tim
      Nov 28 '18 at 16:41











    • @Tim BusyBox is kind of “all shell tools in one binary.” There’s only one executable on disk and tools like ls, cp etc are links to the binary. When it’s run by ls the binary can check from the argument list that it was run as ls and should provide that functionality. When as cp it will function as cp. So regardless of the actual binary file the executed program can have different “name” for how it was being run.

      – Sami Kuhmonen
      Nov 28 '18 at 16:51

















    Thanks. could you be specific about "BusyBox uses links to provide different functionality based on the name with which the executable is called"?

    – Tim
    Nov 28 '18 at 16:41





    Thanks. could you be specific about "BusyBox uses links to provide different functionality based on the name with which the executable is called"?

    – Tim
    Nov 28 '18 at 16:41













    @Tim BusyBox is kind of “all shell tools in one binary.” There’s only one executable on disk and tools like ls, cp etc are links to the binary. When it’s run by ls the binary can check from the argument list that it was run as ls and should provide that functionality. When as cp it will function as cp. So regardless of the actual binary file the executed program can have different “name” for how it was being run.

    – Sami Kuhmonen
    Nov 28 '18 at 16:51





    @Tim BusyBox is kind of “all shell tools in one binary.” There’s only one executable on disk and tools like ls, cp etc are links to the binary. When it’s run by ls the binary can check from the argument list that it was run as ls and should provide that functionality. When as cp it will function as cp. So regardless of the actual binary file the executed program can have different “name” for how it was being run.

    – Sami Kuhmonen
    Nov 28 '18 at 16:51













    2














    By convention, the first argument to a program (i.e. argv[0]) is the name of the program being executed, however it doesn't necessarily have to be.



    For example:



    execl("/bin/ls", "ls", "-l", (void *)NULL);


    In this case, the program to run is the full path to the executable, while the first argument is just the executable name without the path.






    share|improve this answer
























    • Thanks. Out of curiosity, is execl() your favourite out of the exec* family, in cases when several of them are applicable?

      – Tim
      Nov 29 '18 at 0:09


















    2














    By convention, the first argument to a program (i.e. argv[0]) is the name of the program being executed, however it doesn't necessarily have to be.



    For example:



    execl("/bin/ls", "ls", "-l", (void *)NULL);


    In this case, the program to run is the full path to the executable, while the first argument is just the executable name without the path.






    share|improve this answer
























    • Thanks. Out of curiosity, is execl() your favourite out of the exec* family, in cases when several of them are applicable?

      – Tim
      Nov 29 '18 at 0:09
















    2












    2








    2







    By convention, the first argument to a program (i.e. argv[0]) is the name of the program being executed, however it doesn't necessarily have to be.



    For example:



    execl("/bin/ls", "ls", "-l", (void *)NULL);


    In this case, the program to run is the full path to the executable, while the first argument is just the executable name without the path.






    share|improve this answer













    By convention, the first argument to a program (i.e. argv[0]) is the name of the program being executed, however it doesn't necessarily have to be.



    For example:



    execl("/bin/ls", "ls", "-l", (void *)NULL);


    In this case, the program to run is the full path to the executable, while the first argument is just the executable name without the path.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 28 '18 at 16:13









    dbushdbush

    103k13108145




    103k13108145













    • Thanks. Out of curiosity, is execl() your favourite out of the exec* family, in cases when several of them are applicable?

      – Tim
      Nov 29 '18 at 0:09





















    • Thanks. Out of curiosity, is execl() your favourite out of the exec* family, in cases when several of them are applicable?

      – Tim
      Nov 29 '18 at 0:09



















    Thanks. Out of curiosity, is execl() your favourite out of the exec* family, in cases when several of them are applicable?

    – Tim
    Nov 29 '18 at 0:09







    Thanks. Out of curiosity, is execl() your favourite out of the exec* family, in cases when several of them are applicable?

    – Tim
    Nov 29 '18 at 0:09













    2














    You can give anything you want as arg (the second argument).
    Even "nothing" (arg = [NULL]).



    The only effect it will have is that the program called will have as argv exactly what you give it throught arg.



    However, some program expect to always have argv[0] and doesn't check if argv[0] is NULL or not. If you give nothing, you can break the program called.



    Other than that, it should not cause any problem has any sane program will check his argument.






    share|improve this answer






























      2














      You can give anything you want as arg (the second argument).
      Even "nothing" (arg = [NULL]).



      The only effect it will have is that the program called will have as argv exactly what you give it throught arg.



      However, some program expect to always have argv[0] and doesn't check if argv[0] is NULL or not. If you give nothing, you can break the program called.



      Other than that, it should not cause any problem has any sane program will check his argument.






      share|improve this answer




























        2












        2








        2







        You can give anything you want as arg (the second argument).
        Even "nothing" (arg = [NULL]).



        The only effect it will have is that the program called will have as argv exactly what you give it throught arg.



        However, some program expect to always have argv[0] and doesn't check if argv[0] is NULL or not. If you give nothing, you can break the program called.



        Other than that, it should not cause any problem has any sane program will check his argument.






        share|improve this answer















        You can give anything you want as arg (the second argument).
        Even "nothing" (arg = [NULL]).



        The only effect it will have is that the program called will have as argv exactly what you give it throught arg.



        However, some program expect to always have argv[0] and doesn't check if argv[0] is NULL or not. If you give nothing, you can break the program called.



        Other than that, it should not cause any problem has any sane program will check his argument.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 28 '18 at 16:18

























        answered Nov 28 '18 at 16:13









        Tom'sTom's

        2,042420




        2,042420























            1














            If you feel you won't ever want the first array member to differ from the first argument, you can always wrap the function to avoid the repetion:



            int my_execvp(char const *argv) { return execvp(argv[0],argv); }





            share|improve this answer
























            • Thanks. Is execvp the only one out of the exec* family which you can apply the workaround? ( I guess yes)

              – Tim
              Nov 29 '18 at 0:11


















            1














            If you feel you won't ever want the first array member to differ from the first argument, you can always wrap the function to avoid the repetion:



            int my_execvp(char const *argv) { return execvp(argv[0],argv); }





            share|improve this answer
























            • Thanks. Is execvp the only one out of the exec* family which you can apply the workaround? ( I guess yes)

              – Tim
              Nov 29 '18 at 0:11
















            1












            1








            1







            If you feel you won't ever want the first array member to differ from the first argument, you can always wrap the function to avoid the repetion:



            int my_execvp(char const *argv) { return execvp(argv[0],argv); }





            share|improve this answer













            If you feel you won't ever want the first array member to differ from the first argument, you can always wrap the function to avoid the repetion:



            int my_execvp(char const *argv) { return execvp(argv[0],argv); }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 28 '18 at 16:43









            PSkocikPSkocik

            34.7k65579




            34.7k65579













            • Thanks. Is execvp the only one out of the exec* family which you can apply the workaround? ( I guess yes)

              – Tim
              Nov 29 '18 at 0:11





















            • Thanks. Is execvp the only one out of the exec* family which you can apply the workaround? ( I guess yes)

              – Tim
              Nov 29 '18 at 0:11



















            Thanks. Is execvp the only one out of the exec* family which you can apply the workaround? ( I guess yes)

            – Tim
            Nov 29 '18 at 0:11







            Thanks. Is execvp the only one out of the exec* family which you can apply the workaround? ( I guess yes)

            – Tim
            Nov 29 '18 at 0:11




















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53523675%2fdo-the-first-two-arguments-in-exec-functions-contain-redundant-information%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks