1 / 20

Systems Programming and UNIX

Systems Programming and UNIX. What is an OS? Operating Systems provide basic services to applications Hardware interface (disk drives, printers, terminals, etc.) CPU time, memory allocation and management Basic OS processes combined under heading ‘kernel’ Loads first

Download Presentation

Systems Programming and UNIX

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Systems Programming and UNIX • What is an OS? • Operating Systems provide basic services to applications • Hardware interface (disk drives, printers, terminals, etc.) • CPU time, memory allocation and management • Basic OS processes combined under heading ‘kernel’ • Loads first • Remains in main memory during system operation

  2. What is UNIX? • What is UNIX? • Multiuser, Multitasking OS • Multiple processes share CPU time, ‘core’ memory • Systems functions provide interface to hardware control and process management

  3. Logging In • Login establishes user environment and privileges • Password file or authentication database provides information to system on user

  4. Standard Password File Info • Standard password file includes seven fields • username • encrypted password • user ID # • user group # • gecos • home directory • default shell

  5. Shell operation • The login shell provides a command line interpreter for interaction with the system • Different login shells can be designated by the user • bash (default, extension to Bourne) • csh (patterned on C language) • ksh (similar to Bash) • zsh (similar to Bash • cat /etc/shells for list

  6. File system • UNIX file system heirarchical (tree) • Beginning of tree is ‘root’, / • Forward slash designates new directory node (/etc/mail) • Filenames can include any character other than null and /, special chars must be quoted • Paths are absolute if begun with / (indicating root), relative to CWD ( current working directory) otherwise

  7. File descriptors • File descriptors are numeric identifiers of files open to processes • Three standard FD’s (stdin, stdout, stderr) are opened by all shells • All three standard FD’s connect to terminal unless redirected

  8. Buffered and Unbuffered IO • Unbuffered IO • Programmer managed buffers • open, read, write, lseek, close • Buffered IO • Function managed buffers • printf, scanf, putc, getc, etc.

  9. Programs and Processes • A program is an executable file • A process is an instance of a program • Processes all identified by unique number • Three main process control functions • fork • Copy process • exec • Replace process • waitpid • Wait for process to exit

  10. ANSI C • Function prototypes • Describe the structure of functions • Generic pointers (void) • Reduce type casting • Type primitives • Portable, abstracted definitions of types • /usr/include/sys/types.h

  11. Error Handling • Functions typically return negative or null values to indicate errors • Many functions set global var errno to reflect conditions of failure • var errno can be mapped to string • strerror, perror • errno does NOT clear on no error

  12. User and Group ID • Users are identified by unique numbers • superuser (root) identified as 0 • Has unlimited system control • processes are associated with user ID’s and share their privileges • real ID is inherited from the parent • effective ID is set by the file set ID bit • Groups are identified by unique numbers • Groups generally used for group file privileges

  13. Signals • Signals are a means of interprocess communication • User processes can generate signals to other processes, if permissions allow • There are default ‘reactions’ to specific signals • Defaults can be overridden internally

  14. Time Values • Calendar time • # of seconds since midnight, 1/1/70 • Coordinated Universal Time • Process time • Clock ticks (cpu time) • 50, 60, 100 ticks per second

  15. Clock, User and System Time • clock time • process “real time” to run • user CPU time • process time used in instructions • system CPU time • process time used in kernel • user + system = CPU time

  16. System Calls and Library Functions • System calls are entry points to kernel • In UNIX, implemented as C functions • Man section 2 describes • Library Functions may or may not invoke system calls • System related lib functions documented in section 3 • Applications can use either

  17. Manual Tips • Manual pages exist for most system related functions • Section 2 of the manual is used for most system function descriptions • If multiple man entries correspond to a particular keyword, such as ‘read’, you can • use ‘man -a’ to print all entries, rather than just the first • use the ‘whatis’ command, as in ‘whatis read’ to determine what entries exist for the keyword

  18. C Standards • ANSI C • American National Standards Institute • Posix • IEEE (Institute of Electrical and Electronics Engineers)

  19. UNIX Implementations • SVR 4 • AT&T, Sun OS, and 4.3 BSD • POSIX compliant • Solaris major implementation • BSD • AT&T and Berkeley code • POSIX compliant • Available to public as NETBSD and derivatives

  20. Write a program that will do the following: • Print to standard out the associated descriptive text of any given error number input as an argument, or a list of all possible error numbers and descriptions if given a particular flag • Input will be either an error number, or a flag as follows: • –help • print a usage statement to standard out • –all • print a full list of possible error numbers and their descriptions to standard out • Any input NOT within the range of valid error numbers will generate an error message (including a list of defined numbers), and the usage message to standard out. Your program will need to determine all defined error numbers. For purposes of this project, you need not check for definition beyond the range 0-1000.

More Related