Do the first two arguments in exec* functions contain redundant information?
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
add a comment |
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
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
add a comment |
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
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
c linux
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
add a comment |
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
add a comment |
4 Answers
4
active
oldest
votes
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.
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
add a comment |
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.
Thanks. Out of curiosity, isexecl()
your favourite out of the exec* family, in cases when several of them are applicable?
– Tim
Nov 29 '18 at 0:09
add a comment |
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.
add a comment |
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); }
Thanks. Isexecvp
the only one out of the exec* family which you can apply the workaround? ( I guess yes)
– Tim
Nov 29 '18 at 0:11
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Thanks. Out of curiosity, isexecl()
your favourite out of the exec* family, in cases when several of them are applicable?
– Tim
Nov 29 '18 at 0:09
add a comment |
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.
Thanks. Out of curiosity, isexecl()
your favourite out of the exec* family, in cases when several of them are applicable?
– Tim
Nov 29 '18 at 0:09
add a comment |
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.
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.
answered Nov 28 '18 at 16:13
dbushdbush
103k13108145
103k13108145
Thanks. Out of curiosity, isexecl()
your favourite out of the exec* family, in cases when several of them are applicable?
– Tim
Nov 29 '18 at 0:09
add a comment |
Thanks. Out of curiosity, isexecl()
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Nov 28 '18 at 16:18
answered Nov 28 '18 at 16:13
Tom'sTom's
2,042420
2,042420
add a comment |
add a comment |
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); }
Thanks. Isexecvp
the only one out of the exec* family which you can apply the workaround? ( I guess yes)
– Tim
Nov 29 '18 at 0:11
add a comment |
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); }
Thanks. Isexecvp
the only one out of the exec* family which you can apply the workaround? ( I guess yes)
– Tim
Nov 29 '18 at 0:11
add a comment |
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); }
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); }
answered Nov 28 '18 at 16:43
PSkocikPSkocik
34.7k65579
34.7k65579
Thanks. Isexecvp
the only one out of the exec* family which you can apply the workaround? ( I guess yes)
– Tim
Nov 29 '18 at 0:11
add a comment |
Thanks. Isexecvp
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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