HW1b: launchx – A simple C program

Now that you’ve installed Arch Linux, let’s create a simple C program to startup the desktop.

Install twm and xterm

First off, you need to install twm and xterm:

sudo pacman -S xorg-twm
sudo pacman -S xterm

Xterm is the original terminal emulator for the X Window System (which is a windowing system for graphical displays for Linux and other UNIX systems.) Twm is one of the oldest window manager, which is a component of the X Window System that draws borders around application windows, puts up a title bar, and moves/resizes the windows.

Your X installation includes a script called startx, which launches the core components of the X Window System, and then starts up your choices of window manager and other applications, which you can specify in your ~/.xinitrc file. If startx does not find ~/.xinitrc, by default it will start twm window manager and three instances of xterm terminal emulators. Try it! This is the UNIX desktop circa 1989. (You can quit by typing “exit” in the left terminal window.)

What to write

Create a program, named launchx, that forks then executes a shell script specified by a command line argument. If no command line argument is provided, the default script to run is startx.

For example, to run startxfce4, you should be able to run:

./launchx startxfce4

The program should wait for the child process to return, then log your activity to a file in your home directory, named .launchx.log, with the oldest log messages at the top. Each session should append to the log file the current time and message. Here is how your log file should look:

[2016-01-17 15:07:12] Starting startxfce4 session...
[2016-01-17 16:22:34] Your startxfce4 session lasted 1 hour 15 minutes and 22 seconds.
[2016-01-18 03:39:08] Starting startx session...
[2016-01-18 05:44:50] Your startx session lasted 2 hours 5 minutes and 42 seconds.

Note that:

What to submit

You are to submit a single tar.gz file named as follows:

UNI-hw1.tar.gz

Obviously, “UNI” should be replaced with your actual uni. The tarball contains a single top level directory hw1, which contains the following files:

hw1/Makefile
hw1/launchx.c
hw1/screenshot.png (or screenshot.jpg or other common image format)

The last one is the screenshot of your Arch Linux VM running your choice of desktop environment (which may or may not be Xfce as I suggested).


Last updated: 2016–01–20