Cp217
By: Royce Mok • Course Note • 5,641 Words • May 16, 2015 • 660 Views
Cp217
CP217 - Final Exam Review
By: Robin Sharma
Unix Architecture:
- System resources:
1. CPUs
2. memory, disk
3. devices: i/o
4. process mgmt
5. IPC
6. timers
7. Networking
- OS is a resource manager. It takes the form of a set of software routines that allow users and application programs to access system resources in a safe, efficient and abstract way
- kernel is in direct control of the underlying hardware. The kernel provides low-level device memory and processor mgmt functions, eg. dealing with interrupts from hardware devices, sharing the processor among multiple programs, allocating memory for programs etc.
System Calls:
- basic hardware-independent kernel services are exposed to higher-level programs through library of system calls.
Application Programs: ex. word processors, spreadsheets etc. make use of system calls
System Utililty programs:
- simple but useful application programs that come with the OS, eg. programs which find text inside a group of files), make us of system calls.
Shells and GUIs
- applications and system utilities are launched using a shell
System programs and programming:
- system programs are those that direclty inferface with the kernel services and system calls
Examples:
- ls, cd, pwd, who
- shell, text editor, compiler, system daemons, core utils etc.
- used by other programs or by users directly
- system programming is to write these types of system programs
Who:
purpose: list users currently logged on
output: logname, terminal, time, from where
How does it work?
open utmp
while(~eof) {
read record
display info
}
close file
Where is this information?
*utmp - holds entries for currently active user login sessions
wtmp - where all log entries are simply appended to the end of the file, acts as historcial utmp
btmp - records failed login attempts
struct utmp {
char ut_user[8]; /* User login name */
char ut_id[4]; /* /etc/inittab id(usually line #) */
char ut_line[12]; /* device name (console, lnxx) */
short ut_pid; /* short for compat. - process id */
short ut_type; /* type of entry */
struct exit_status ut_exit; /* The exit status of a process */
/* marked as DEAD_PROCESS. */
time_t ut_time; /* time entry was made */
};
Question: How do I read stucts from a file?
ans: use open(), read(), and close()
fd = open(name, mode) <-- creates a connection to a file
name = char *
mode = O_RDOLNY, O_WRONLY, O_RDWR
returns -1 on error OR a file descriptor int on success
n = read(fd, array, numchars)
transfer numchars from file to the array
returns number of chars actually transferred or -1 on error