Users and Files: who is first
Prof. Brian D. Davison
Computer Science & Engineering, Lehigh University
Announcements
- Reminder of scripting project due Thursday
- Today's schedule
- Return Short quiz #7, range 4-10, average=6.3
- Return homework #4, range 4.5-9.5, average=8.5
- Start Understanding UNIX Programming
Files and Users
- Today we will write a version of the who utility.
- In the process, we will learn about files, users, time, and buffering.
How does who work?
- What does it do?
- How does it do it?
- How can we learn about the details?
How does who work?
- What does it do?
- Purpose: list users currently logged on
- Output: logname, terminal, time, from where
- We can see what it does by running the command.
- ... and by using the system manual pages.
How does who work?
- How does who do it?
- Where do we start?
- By reading the man page (and follow the "see also" links)
- Searching the manual for relevant keywords
- Read relevant .h files in /usr/include
How does who work?
- Answer (for Solaris): calls library functions that
- open wtmp (or equivalent) file
- reads a record
- closes wtmp
- All who has to do is
- call library functions
- display information from structure provided
- Now we can write who.c
Close, but still needs work
- How to we get it to look good?
- Suppress old entries
- Format time
- Need to look some more in the manual and header files
Fixes for who2.c
- Suppress blank entries
- check ut_type (se utmp.h>
- Format time
- ctime() converts to string
- Unix stores time as seconds seince the beginning of the epoch
- Result: who2.c
cp (read and write)
% cp sourcefile copyfile
What does cp do?
How does it do so?
cp (read and write)
% cp sourcefile copyfile
What does cp do?
- Answer: creates or truncates a file, then writes data into it
How does it do so?
- Answer: let's find out by searching the manual pages