Re: /sbin/reboot: symbolic link to `halt'
On Sun, Aug 16, 2009 at 9:22 PM, Sven Joachim<svenjoac@gmx.de> wrote:
> On 2009-08-16 22:36 +0200, Chris Bannister wrote:
>
>> I noticed that /sbin/reboot is a symbolic link to /sbin/halt. How does
>> the system "know" the difference?
>
> The program notices how it is called and behaves accordingly. Programs
> written in C can get information about their name in argv[0].
Well, the parent process sets argv[0], just like it sets argv[1] and
following. The idea that argv[0] should be the name with which the
program was invoked is just a convention.
It's not a commonly broken convention, though. Login shells are
started with '-' as the first character of argv[0]. The only other
example I can think of is that ldd used to call programs with argc==0
and argv[0]==NULL in order to get the dynamic linker to spit out the
list of shared libraries. These days, this is done differrently and
argv[0] is no longer special on Linux from that point of view. Not
sure when the changeover happened, it could be the a.out->ELF switch.
James.
Reply to: