4 ms·
maybe you can start with the classic exercise of writing your own shell. That’s a great way to learn most of the fundamentals of systems programming (and usuall
by funkaster 5y ago
maybe you can start with the classic exercise of writing your own shell. That’s a great way to learn most of the fundamentals of systems programming (and usually the go-to exercise for that class on CS courses)
- corty 5y agoYep. Write a grep and find (IO-loop, filesystem), a shell (child processes, signals), a simple nmap-replacement (network, DNS), a forking and a multithreaded webserver (more network, more children, synchronisation), a clock with seconds display and something that synthesizes and plays music on keypress (timing, waiting). Everything just in the simplest sense, no fancy features needed: the grep just needs a string parameter to search for and some files, the shell doesn't need completion, scripting or variables, just execution and background jobs. For the webserver, just serve some static files from the URL, ignore security, concentrate on getting lots of clients served at the same time however. Bonus points if you make the main process/thread gather meaningful statistics/logs and not screw up concurrency. Make sure to learn the right synchronisation primitives and use them properly. For the clock, make sure to explore sleep-based, loop-based and signal-based approaches and compare them. Get all three second-ticks to be in sync with your pocket watch and not skip/delay/hang. The music exercise is similar, just event-based (you get to handle key input and buffer low or tick events), either with something like select/epoll or multiple threads. The music itself is not interesting, a simple sine or rectangle signal suffices. But of course reaction time should be low and sound should be glitch-free. What is missing from the above but important are the security aspects of systems programming, most of which are either problems with certain languages (learn how to avoid, recognize and exploit a simple buffer overflow, format string exploit), security aspects around file creation (especially temporary files, but also general symlink attacks), SUID-bits, permissions/ACLs/MAC and generally privilege separation. Those aren't easy to put into learning-by-doing exercises, because you would need an attacker to slap you over the head when you make a mistake there ;) As a programming language, for Linux/Unix I would strongly recommend using C, not C++, not anything else. Use libc or plain syscalls, nothing fancier. When you have mastered the above in C, you know how to appreciate other, better languages, but also know where those may be lacking. If you just do the above in Python, you learned nothing about systems programming and everything about Python lib idiosyncracies