Why bother with argv[0]?
wietzebeukema.nl
Why bother with argv[0]?
1–10 of 277 posts
Re: Why bother with argv[0]?
#2Also claiming that the windows API to call a new process is good… wow… I guess he's never had to pass a filename with quotes and spaces in its name. The API expects you to do the escaping yourself. Yes it needs to be escaped, because it's all one single string.
Re: Why bother with argv[0]?
#3Re: Why bother with argv[0]?
#4Android does this for most common shell commands. Toybox and busybox are examples of such implementations.
Re: Why bother with argv[0]?
#5Re: Why bother with argv[0]?
#6Re: Why bother with argv[0]?
#7On desktop machines, perhaps, but this is certainly not true on all platforms Linux runs on.
Re: Why bother with argv[0]?
#8It is sometimes used to allow one binary to be the symlink target of hundreds of commands. Android does this for most common shell commands. Toybox and busybox are examples of such implementations. https://github.com/landley/toybox https://en.m.wikipedia.org/wiki/BusyBox
Re: Why bother with argv[0]?
#9I'm fascinated by the intersection of argv[0], and the execve behavior of replacing the calling program with the called one.
Aside from that, I quite like argv[0], for a much more limited set of reasons than considered in this interesting and comprehensive article. I like the ability to "retitle" a process to put a useful, descriptive, or branded name in there to be seen by ps, et al.
NodeJS also exposes this feature, but not quite as you might expect. Whereas in C, setting argv[0] from within the program's execution context will alter what is observed by ps, in NodeJS process.argv is just a descriptive getter. Setting its slots has no effect outside of its context.
But this is where process.title steps in. Setting process.title allows you to (in an OS-dependent way) change the name reported in ps and similar tools.
Read more here: https://nodejs.org/api/process.html#processtitle
Please don't kill argv[0], its lease hath all too short a date