This is a fun one.  VERY philosophical, yes.

Fuzzy, you're mixing up sym-link and hard link in the chain-walking
paragraph.  But you're right about unlink() breaking the relationship.
 So I am confused about your reply.  A sym-link is a soft link.  It's
the pointer (which you correctly identified as slowing things down ...
ever so slightly).  A hard link is a directory reference to the same
inode.  It's the original.  (From the days when Unix did not have
sym-links.)  It cannot span filesystems (as Kim mentioned).  A hard
link is simply a second name to some file (some inode) which is
already known by a prior name.

When you do an 'ls -l', the second column is the link count.  Notice
that directories will always have a link count greater than one.  A
file which has been hard linked will have a link count greater than
one.

Hard links cannot span filesystems.  Hard links (that you make
yourself) also cannot point to directories.  I have tried.  Don't.
You won't like it.  Let the kernel handle all hard linking of
directories.  If you play around with it (bypassing the 'ln' command
and calling link() directly) you will make the kernel unhappy because
you played in its space.  Unhappy kernels get emotional.  (Means they
might panic.)

John, dunno why Fedora would have an affinity for hard links or soft
links.  I use both, but more often use sym-links (soft links,
pointers).  The cost of sym-linkery is negligible and only affects
launch.  Once the file is open or the program is invoked, any handles
are associated with the inode of the real file, not the pointer, not
even the "real" name.  The argv[0] switcheroo you seek works fine with
either soft links or with hard links.  No change there.

There is no easy answer whether to use a soft link or a hard link.
You have to think about it.  (Please forgive me if I'm stating things
you already know.)

One of the rules of good systems programming (that some don't know and
others don't follow) is to separate software residence from software
reference.  If you're simply making an alias, chances are that you
really want a sym-link, a pointer.  If something else (or someone
else) manages the original file and you make a hard link, the original
could be deleted before being replaced and then you have broken the
relationship.  So if it is something you don't maintain, then
generally avoid hard linking it.

Nothing wrong with using hard links.  If you have one executable and
it changes personality based on the command name and all "names" live
in the same directory, then make them hard links.  But if the names
are in other directories (which might get moved to other filesystems)
or if the original could get replaced then a sym-link is probably
safer.

Other Stuff ... for the Trivia Addicts

Linux allows you to hard link a sym-link (kinky!), but this is not
always portable.

A file's link count can drop to zero.  When it does, the file is
deleted.  A file which is open and has been deleted will have a link
count of zero but will still have its inode and will still occupy
blocks on disk ... until it is closed, at which time the kernel will
clean everything up.  A link count of zero in 'ls -l' output is an
error.  If you see that, you should run 'fsck' soon.

BusyBox is a package which contains one single mondo executable that
handles EVERYTHING.  It uses the argv[0] trick to change command
personalities.  Last time I build it, I seem to recall that it used
sym-links.  But a tool like BusyBox could just as well use hard links.
 (Since often it puts all the "verbs" in the same directory.)

-- R;   <><





On Mon, Jan 4, 2010 at 16:22, McKown, John
<[email protected]> wrote:
> I just noticed something on my Linux desktop that is "different" from the way 
> that I do things. When I want to be able to run a command which acts 
> differently depending on the command name which invoked it, I always use a 
> symlink for the alternate names. I just noticed that Fedora 11 doesn't. I 
> curious if a hardlink is that much more efficient than a symlink when it 
> comes to loading a program. Or is there some other reason to use a hardlink 
> rather than a symlink. I use a symlink because I can then modify the program 
> and all the other names are automatically using the new version of my program.
>
> John McKown
> Systems Engineer IV
> IT
>
> Administrative Services Group
>
> HealthMarkets(r)
>
> 9151 Boulevard 26 * N. Richland Hills * TX 76010
> (817) 255-3225 phone * (817)-961-6183 cell
> [email protected] * www.HealthMarkets.com
>
> Confidentiality Notice: This e-mail message may contain confidential or 
> proprietary information. If you are not the intended recipient, please 
> contact the sender by reply e-mail and destroy all copies of the original 
> message. HealthMarkets(r) is the brand name for products underwritten and 
> issued by the insurance subsidiaries of HealthMarkets, Inc. -The Chesapeake 
> Life Insurance Company(r), Mid-West National Life Insurance Company of 
> TennesseeSM and The MEGA Life and Health Insurance Company.SM
>
>
> ----------------------------------------------------------------------
> For LINUX-390 subscribe / signoff / archive access instructions,
> send email to [email protected] with the message: INFO LINUX-390 or visit
> http://www.marist.edu/htbin/wlvindex?LINUX-390
>

----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390

Reply via email to