Member-only story
Understanding System Programming: Writting the who command
When working with operating systems, you will often interact with system resources using system calls. Learning how to interact with system resources is the purpose of the study of system programming. We will take a look at common command line utilities in Linux, learn how they work, and learn how to implement our own versions of them. In doing this, we will gain a good understanding of how operating systems handle resources, and how a program can interact with them.
The command we will look at in this article is the who command. The purpose of the who command is to show you who is currently using a system you are logged into. If I run the who command on my current Linux installation, I get the following results.
The information displayed by the who command is the username of the person who is logged in, the type of terminal the user is using, the date that they logged in, and the location that they logged in from. The first question we need to ask when trying to implement this command is, how does the current command do it? Where does this information come from, and how do we access it?
To figure out how a command actually works, there are four main techniques that are valuable:
1. Read the manual
2. Search the manual
3. Read the header files
4. Read the “see also” links