I'm going to comment with respect to version 2.2 of the Linux kernel here so some of the follow may not apply to your system or even the modern kernel version. Still I find it really interesting and I think you will too.

Today Linux's main binary file format is called ELF (Executable and Linking Format). Linux has also supported other binary formats, these are options in your kernel setup.

When you go to run a file as if it were a program the file is checked to see if you have the execute permission on it. After that check the kernel tries to match the file to a known format (ELF, a.out, and so on). This matching is done by looking for "magic numbers" in the file somewhere. I think Microsoft DOS .EXE files always start with the the first two bytes being the ASCII letters "MZ" for example.

The last check in the list of file formats is for a file that starts with "#!" because this has been used for years in Unix-like systems to mean that the kernel should go find the filename specified after the "#!" and run that program. The name of the file you actually tried to execute gets passed as an argument to the process really created from the "#!" filename.

Though it is not often done (that I know of) you can actually tell Linux to match executable file formats based on a filename extension like DOS and I think windows does for .EXE files. (I don't know how Windows deals with these things but I think it is based on filename extension. For that matter I don't know how DOS does it either.)

If you're interested in this look for the binfmt_misc.txt file in the Documentation directory in the kernel source tarball. Before you do decide to use it I caution that I don't know of any companies that use it as a standard. The "#!" line is going to be much more portable.

In reply to Re: Perl Directive by superfrink
in thread Perl Directive by Echo Kilo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.