Arch Linux: a developer-friendly Operating System

I have been using Arch Linux as the working environment for nearly 2 years. Generally speaking, the experience is very good, and I want to recommend it for more people, especially software engineers.

Because I am a developer, one SSH client is mostly enough, and fascinating desktop doesn’t appeal to me. Since Arch Linux is “rolling release” mode, it means I can always get the newest kernel and software packages (one “pacman -Syu” command will refresh the whole system), and my favorite thing is to make use of the newest functions provided by compiler and kernel . On the contrary, one pain point of distributions whose mode are “point release” is sometimes you need to compile the vanilla kernel yourself if you want to try some up-to-date features (E.g., use eBPF on RHEL 7) .

The package management system is another killer feature. For instance, I used to try to develop OpenMP program using clang. Not similar as gcc, clangrequires additional package:

# pacman -S clang
......
Optional dependencies for clang
    openmp: OpenMP support in clang with -fopenmp
    python2: for scan-view and git-clang-format
......

The prompt not only shows me that I need to install openmp package, but also requires “-fopenmp” option to compile OpenMP program. This is very humanized. I tried to enable OpenMP feature of clang on some other OSs, and the process is not as smooth as Arch Linux.

Last but not least, Arch Linux community is friendly, I can always get help from other enthusiastic guys.

For me as a programmer, what I need is just a stable Operating System which can always provide latest software toolchains to meet my requirements, and I don’t want to spend much time to tweak it. Arch Linux seems fulfill these demands perfectly. If you have simple requirement as me, why not give it a shot?

The anatomy of uptime&w commands on OpenBSD

On OpenBSD, uptime and w are actually the same program:

$ ls -lt /usr/bin/uptime /usr/bin/w
-r-xr-xr-x  2 root  bin  18136 May 30 12:53 /usr/bin/uptime
-r-xr-xr-x  2 root  bin  18136 May 30 12:53 /usr/bin/w

and the source code is usr.bin/w/w.c.

Compare the outputs of uptime and w:

$ uptime
10:59AM  up 7 days,  1:51, 1 user, load averages: 0.00, 0.00, 0.00
$ w
10:59AM  up 7 days,  1:51, 1 user, load averages: 0.00, 0.00, 0.00
USER    TTY FROM              LOGIN@  IDLE WHAT
root     p0 10.217.242.57     9:10AM     0 w

You can see the uptime just displays the first line of w, and w also shows the login users’ information.

w uses clock_gettime to get system up time:

if (clock_gettime(CLOCK_BOOTTIME, &boottime) != -1) {
    ......
} 

and getloadavg to retrieve system load average int the past 1, 5, and 15 minutes:

int
getloadavg(double loadavg[], int nelem)
{
    ......
    mib[0] = CTL_VM;
    mib[1] = VM_LOADAVG;
    size = sizeof(loadinfo);
    if (sysctl(mib, 2, &loadinfo, &size, NULL, 0) < 0)
        return (-1);
    ......
}

The current user login information is kept in /var/run/utmp, and it is composed of utmp struct:

struct utmp {
    char    ut_line[UT_LINESIZE];
    char    ut_name[UT_NAMESIZE];
    char    ut_host[UT_HOSTSIZE];
    time_t  ut_time;
};

utmp.ut_line is the login terminal (remove “tty” prefix); utmp.ut_name is the login user name; utmp.ut_host is the login address and the utmp.ut_timeis the login time. These are the first 4 columns of every line:

USER    TTY FROM              LOGIN@  IDLE WHAT
root     p0 10.217.242.57     9:10AM     0 w

The IDLE column displays how long has passed since you last operates on terminal:

if ((ep->idle = now - stp->st_atime) < 0)
        ep->idle = 0;

and WHAT shows the current process.

Fix “==> ERROR: options array contains unknown option ‘!upx'” on ArchLinux

You may bump into following error when installing packages from AUR:

$ makepkg -si
==> ERROR: options array contains unknown option '!upx'

One workaround is open the PKGBUILD file, and spot the line which contains options:

......
options=('staticlibs' 'libtool' '!upx')
......

Remove the !upx, then you can build it now.

Reference:
dropbox: unrecognized !upx in the options array.

 

Fix “error while loading shared libraries: libalpm.so.10” on ArchLinux

Today, when I tried to use yaourt to install some software, the following error happened:

......
package-query: error while loading shared libraries: libalpm.so.10: cannot open shared object file: No such file or directory

The root cause is the libalpm in system is already libalpm.so.11:

$ ls -lt /usr/lib/libalpm.so*
lrwxrwxrwx 1 root root     17 Jun  1 00:32 /usr/lib/libalpm.so -> libalpm.so.11.0.0
lrwxrwxrwx 1 root root     17 Jun  1 00:32 /usr/lib/libalpm.so.11 -> libalpm.so.11.0.0
-rwxr-xr-x 1 root root 223616 Jun  1 00:32 /usr/lib/libalpm.so.11.0.0

But the package-query is still searching libalpm.so.10:

$ ldd /usr/bin/package-query
        linux-vdso.so.1 (0x00007fffb1d8d000)
        libcurl.so.4 => /usr/lib/libcurl.so.4 (0x00007f4baee32000)
        libyajl.so.2 => /usr/lib/libyajl.so.2 (0x00007f4baec28000)
        libalpm.so.10 => not found
        libc.so.6 => /usr/lib/libc.so.6 (0x00007f4bae86c000)
        libnghttp2.so.14 => /usr/lib/libnghttp2.so.14 (0x00007f4bae647000)
......

The solution is removing yaourt and package-query, and re-intall them:

$ sudo pacman -Rn yaourt package-query
$ sudo pacman -S fakeroot
$ git clone https://aur.archlinux.org/package-query.git
$ cd package-query
$ makepkg -si
$ git clone https://aur.archlinux.org/yaourt.git
$ cd yaourt
$ makepkg -si

That’s it!

Beware “No such file or directory” error in using ksh

Check following simple script:

#!/usr/bbin/python
print("hello world!")

I misspelled python path intentionally. On Linux Bash, it reported following error:

$ ./hello.py
-bash: ./hello.py: /usr/bbin/python: bad interpreter: No such file or directory

It prompted me that “/usr/bbin/python” couldn’t be found. While on OpenBSD ksh:

$ ./hello.py
ksh: ./hello.py: No such file or directory

It gave an illusion that hello.py didn’t exist. So be careful about this error information if you use ksh.