Schedule
Labs
Assignments
TA office hours
Topic videos
Some course notes
Extra problems
Lecture recordings
Considerable cleverness is possible in the determination of sleep() strategy for autologout.
Here's the algorithm.
To start up, you call ttyname() and getppid() and all that initialization stuff, of course.
In the big loop, you first do this: stat the terminal, and call time(), and see if we should be doing the killing thing (and if so, do it and exit).
If it's been idle for less than the killing time, sleep() for the remaining number of seconds. E.g. if we've been idle for 123 seconds and we're killing after an hour of idleness, sleep for (3600-123) seconds.
And that's it! The call to time() at the beginning of the big loop will take care of EAGAIN issues (if the sleep() doesn't actually sleep the full amount).