A repo containing example code and exercises from The Linux Programming Interface book.
The exercises directory containers answers/solutions to the exercises in the book. Each chapter has its own subdirectory, chXX. For exercises that are just questions, the answer is in a markdown file matching the exercise number, e.g., 3-1.md for exercise 3-1. For exercises that require code, there is a subdirectory named after the exercise program, e.g., teeclone for exercise 4-1 to replicate the tee command, which may not necessarily match the exercise number. Regardless, the subdirectory will contain a README.md file with the exercise description, a main.c file containing the solution, and optionally a test.sh script to test the solution.
An exercise program may be build, tested, and run using the just command runner.
For example, to build and run the teeclone program in chapter 4, you would use the run command:
$ python3 -c 'print("A" * 256, end="")' | $(just run 04 teeclone) test.txt | wc -c
256Note that the just run command does not actually run the program, but rather builds it and returns the path to the executable. This is done in order to run the program without just interfering with I/O redirection, flags parsing, etc. Therefor, to run the program, you would wrap the just run command in a subshell, as shown above.
To simply build the program, you can use the build command:
just build 04 teecloneSimilarly, to test the program, you can use the test command:
$ just test 04 teeclone
./exercises/ch04/teeclone/test.sh
[-] Testing with buffer size 256 and flags ''
[+] Test passed: 256 bytes printed and 256 bytes written to build/ch04/teeclone/test.txt
[-] Testing with buffer size 256 and flags '-a'
[+] Test passed: 256 bytes printed and 512 bytes written to build/ch04/teeclone/test.txt
[-] Testing with buffer size 9182 and flags ''
[e] Expected 9182 bytes printed, but got 12288In contrast to the run command, the test command will run the program without requiring a subshell.
A full list of just commands is available via just --list.
$ just --list
Available recipes:
build CHAPTER EXERCISE
clean
format
run CHAPTER EXERCISE
test CHAPTER EXERCISE