Introduction to
Operating Systems All computers that we interact with run an operating system
There are several popular operating systems Operating Systems
OS consists of a suite of basic software Operating Systems Compilers Text editors Shells Graphical interfaces Debuggers and much more And most importantly, the Kernel The OS Kernel is the chief software program that runs on a computer In the context of programming, OS usually refers to the kernel
Hardware Abstraction Operating Systems Function Resource Management Standardized Interface Security Performance
Hardware speaks binary A binary code can mean different things to different hardware Operating Systems Hardware Abstraction OS abstracts hardware The OS kernel is the layer separating hardware and applications Application software run in an environment where direct access to hardware is extremely limited Applications request the Kernel to perform hardware operations on its behalf Application Software Utilities Libraries Kernel Hardware
Resources are shared among applications Like CPUs, memory and input/output devices Operating Systems Kernel scheduler enables multitasking Allows more applications to run than there are CPUs Kernel provides memory protection Resource Management So that one application cannot disrupt others Mediates multiple device accesses Multiple programs communicating over the network for instance
System Calls Is how applications request the OS to perform a service on the application s behalf Operating Systems Standardized Interface Applications execute a special set of instructions on the CPU to invoke a system call Transfers control to the kernel to perform the function Applications resumes execution when function completes Standard Libraries Built on top of system calls to provide higher level functions Like buffered file I/O
Standardized System calls and Libraries Operating Systems Standardized Interface Documented names, parameters, return values and behavior of these functions Allow the programmer to tell the operating system to perform a function without need to consider The underlying hardware The OS implementation or version These standards constitute the Application Programming Interface (API) for an OS or family of OSes Applications that closely follow the standard API can be ported easily.
Operating Systems Security Access Control Enforce access restrictions on files among different users Network security Remote access control. Who can login remotely.
Operating Systems OS can use knowledge of underlying hardware and application behavior to enhance performance and efficiency Performance Transparent to the application Can use special features of the hardware to speed up operations Resource sharing between applications to maximize efficiency Cached access to filesystems is a good example
AT&T Unix Operating system developed in the 1970s at Bell Labs by a team led by Ken Thompson and Dennis Ritchie Operating Systems Unix GNU Project 1972, rewritten in C. A language originally developed by Dennis Ritchie at Bell Labs Unix was liberally licensed to universities and firms, including source code Led to its increased popularity in academia 1982, UNIX was commercialized. Source code was not included anymore Cover. Oct 20, 1982 issue Electronics
POSIX The official standard that defines Unix-like operating systems Operating Systems Unix GNU Project Large number of operating systems were derived from the original Unix Effort to standardize the Unix API to ease portability of software between different derivatives Eventually included commands, utilities and standard libraries Resulted in IEEE POSIX standard which evolved into the Single Unix Specification (SUS)
Operating Systems Unix GNU Project GNU Project A year after UNIX was commercialized, Richard Stallman announced a project to create a completely free UNIX-like OS By 1990, GNU was mostly complete except for a kernel
In 1991 Linus Torvalds starts a hobby project called Hello everybody out there using minix I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones. This has been brewing since april, and is starting to get ready. I'd like any feedback on things people like/dislike in minix, as my OS resembles it somewhat (same physical layout of the file-system (due to practical reasons) among other things). I've currently ported bash(1.08) and gcc(1.40), and things seem to work. This implies that I'll get something practical within a few months, and I'd like to know what features most people would want. Any suggestions are welcome, but I won't promise I'll implement them :-) Linus (torvalds@kruuna.helsinki.fi) PS. Yes - it's free of any minix code, and it has a multi-threaded fs. It is NOT portable (uses 386 task switching etc), and it probably never will support anything other than AT-harddisks, as that's all I have :-(. Linus Torvalds[14] GNU/ was born
Basics Users and Groups is a multi-user, multi-tasking OS All files managed by the OS are associated with a User and a Group Users and Groups are defined in a database which also defines a mapping with an integer user ID (uid) and group ID (gid) uid associated with a file is the owner of that file Special user root (uid 0) has unrestricted privileges Can access/modify all files Can change settings that can affect the operation of the system
Basics Process Programs are executable code stored on disk Processes are programs that are being executed by the OS Kernel assigns an integer process id (pid) to each process and keeps track of it Process can be in multiple states between start and termination Running Stopped Sleeping
Basics Files A file is anything that can be located by a unique pathname Processes can open files For a process, opening a file creates a new File Descriptor Subsequent read/write operations can be performed on the file descriptors Files may or may not have data stored on some media Unix abstracts devices as files Three file descriptors are automatically created when a process starts fd 0: standard input (stdin) fd 1: standard output (stdout) fd 2: standard error (stderr) These standard streams can be redirected to files
/ Directory Tree Basics Navigating the Filesystem All files exist within a directory (Folder in Windows) Hierarchical directory structure rooted at / Pathname specifies the location of a file or directory within the hierarchy / is the pathname directory separator home user1 ebasheer thesis.txt info.txt bin sbin mnt /home/ebasheer/thesis.txt
Mount Point Basics Navigating the Filesystem No drives unlike Windows All files and directory names are in the same hierarchy / home user1 ebasheer Regardless of where they are physically stored thesis.txt Or what underlying storage format/medium is used That is, the hierarchy can span multiple filesystems info.txt bin sbin mnt /home/ebasheer/thesis.txt
File Links Basics File Links Unique files within a single filesystem are identified by inode numbers File names are associated with inode numbers Hard Link Multiple file names referring to the same inode number Symbolic Link Special inode that contains a pathname to another file
Bash Shell The shell is the text based interface to the OS Basics Also referred: console, terminal or command-line Bash is the default shell of virtually all distributions Shell accepts commands Built-in or external Shell Bash is a complete programming language Commands can be combined with control structures e.g. execute command2 if command1 is successful Shell Prompt Shell signals to user that it is ready to accept commands ebasheer@strobe:~$ root@strobe:~#
Current Working Directory Basics Shell Every process has current working directory defined when it starts Including the shell Directory and file related commands operate on the cwd by default The pwd command prints the current working directory to stdout ebasheer@strobe:~$ pwd /home/ebasheer
Command History Basics Shell history command writes out a list of all previous commands executed at the prompt Up/Down arrow to browse through the history Incremental search through history Start: CTRL+r Accept: Esc Abort: CTRL-g
ls List the contents of the current working directory Basics Basic Commands $ ls Desktop Dot files not listed by default Options modify the behavior of commands -a option for ls lists all files Documents $ ls -a....adobe.bash_aliases.bash_history.bash_logout.bashrc Downloads Desktop.dmrc Documents Downloads.gconf.gimp-2.8.gitconfig imgs info opt.gnupg.gtkrc-2.0.gvfs.iceauthority imgs.imgs info tmp VirtualBox VMs.macromedia.modulerc.mozilla.nano.nv.nvidia-settings-rc opt work.selected_editor.ssh.ssh-20160816.sudo_as_admin_successful.thumbnails.thunderbird tmp.vimrc VirtualBox VMs.virtualenvs.wget-hsts work.xauthority.xdefaults
ls Basics List the contents of the current working directory Basic Commands GNU commands support long and short versions of options $ ls --all....adobe.bash_aliases.bash_history.bash_logout.bashrc Desktop.dmrc Documents Downloads.gconf.gimp-2.8.gitconfig.gnupg.gtkrc-2.0.gvfs.ICEauthority imgs.imgs info.macromedia.modulerc.mozilla.nano.nv.nvidia-settings-rc opt.selected_editor.ssh.ssh-20160816.sudo_as_admin_successful.thumbnails.thunderbird tmp.vimrc VirtualBox VMs.virtualenvs.wget-hsts work.xauthority.xdefaults
Short options can be strung together ls -a -l same as ls -al Basics Basic Commands $ ls -al total 288 drwxr-xr-x 36 ebasheer drwxr-xr-x 4 root drwx------ 3 ebasheer -rw-rw-r-- 1 ebasheer -rw------- 1 ebasheer -rw-r--r-- 1 ebasheer -rw-r--r-- 1 ebasheer drwx------ 24 ebasheer drwxr-xr-x 25 ebasheer drwx------ 3 ebasheer drwxr-xr-x 4 ebasheer -rw-r--r-- 1 ebasheer ebasheer root ebasheer ebasheer ebasheer ebasheer ebasheer ebasheer ebasheer ebasheer ebasheer ebasheer 4096 4096 4096 342 7535 220 3893 4096 4096 4096 4096 26 Aug May May Aug Aug May Aug Aug Aug May Aug May 22 9 16 1 22 2 17 22 10 18 22 2 17:29 10:48 15:03 11:09 16:32 12:17 11:03 16:02 17:29 17:14 10:38 18:46....adobe.bash_aliases.bash_history.bash_logout.bashrc.cache.config.dbus Desktop.dmrc
Basics Basic Commands Long and short options can be mixed ls --all -l Most commands have a --help or -h option More detailed information about command usage in man pages To view the man page for a command man <command> Man page for cp command man cp
Basic Commands Man Pages Some options require an argument $ pgrep -u pgrep: option requires an argument -- 'u' $ pgrep -u avahi 5387 5399 $ pgrep -uavahi 5387 5399