One of the options when installing the FreeBSD operating system (or when changing its setup any time after the installation) is Linux "emulation". This allows the user to run software distributed as Linux binaries (without source code) under FreeBSD.

The two systems use different kernel interfaces: Under Linux parameters are passed in the registers; under FreeBSD on the stack (i.e., the same as in C). That is why an "emulation" is needed to run Linux software under FreeBSD.

If I have been ostentatiously putting the word "emulation" into quotation marks, that is because Linux "emulation" is actually a misnomer.

A true emulation would insert an extra layer of code between the software and the kernel. It would intercept all Linux system calls, make the appropriate FreeBSD system calls, and return back to the application software. In other words, it would slow the code execution down.

Not so under FreeBSD. The FreeBSD kernel contains a dual interface: Its own, and that of Linux. Without the Linux "emulation" option installed, all software is assumed to be using the native FreeBSD kernel interface.

With the option installed, all executables are examined. If they are compiled for FreeBSD, they use the FreeBSD interface. If for Linux, they use the Linux interface. Hence no extra layer of code and no slowdown.

Indeed, many say that FreeBSD runs native Linux software faster than Linux itself.

For example, one of the companies that created the Oscar-winning and mind-boggling special effects for The Matrix used the Linux version of Pixar software. One of their employees, experienced with FreeBSD suggested they try his favorite OS. They did, and found that the software ran considerably faster under FreeBSD, and they stuck with it.

What can I say? There is no spoon.

One trick that is sometimes necessary to run Linux binaries under FreeBSD is to fool the binary into thinking it is running on Linux. Sometimes the binary will complain "This isn't Linux -- can't run" and you then have to say, "Sure -- this is Linux -- trust me!" For example, Matlab and Maple both complain that they don't support FreeBSD when you try to run them. By using a compatible shell, they can be tricked into running on FreeBSD. This typically consists of changing lines in a shell script, e.g.

#!/bin/sh

to

#!/compat/linux/bin/sh

and then commands like uname will return "Linux" etc., and the binary runs without problem.

Log in or register to write something here or to contact authors.