150 likes | 263 Views
Linux in More Detail. Shirley Moore svmoore@utep.edu www.cs.utep.edu/svmoore CPS5401 August 29 , 2013. The Kernel. The software layer that manages and allocates system resources (e.g., CPU, RAM, devices) Services provided by the kernel Process scheduling preemptive multitasking
E N D
Linux in More Detail Shirley Moore svmoore@utep.edu www.cs.utep.edu/svmoore CPS5401 August29, 2013
The Kernel • The software layer that manages and allocates system resources (e.g., CPU, RAM, devices) • Services provided by the kernel • Process scheduling • preemptive multitasking • Memory management • virtual address spaces • Provision of a file system • Creation and termination of processes • Access to devices • Networking • Provision of a system call application programming interface (API)
Linux Kernel Versions • kernelnewbies.org/LinuxChanges/ • kernelnewbies.org/LinuxVersions/ • Most recent version is 3.10, released on30 June 2013 • perf_events for accessing hardware counters merged into the Linux kernel starting with version 2.6.31. • To access hardware counters from within a KVM virtual machine, you need Linux version 3.3 or later.
Kernel mode vs. user mode • Areas of virtual memory are marked as being part of user space or kernel space • When running in user mode, CPU can only access memory in user space – i.e., user processes cannot access kernel instructions and data structures directly • When running in kernel mode, CPU can access both user and kernel memory space • Some operations can be performed only while the processor is operating in kernel mode • accessing memory management hardware • initiating device I/O operations • e.g., “A process can write data to a file” should really be “A process can request that the kernel write data to a file”. • The shell runs as a user process.
File Permissions • Linux systems are multi-user environments where multiple users run programs and share data. Files and directories have three levels of permissions: User, Group, and Others. • The types of permissions a file can have are Readable, Writeable, and Executable
Changing Permissions • chmod – command to change permissions on a file or directory • chgrp – command to change group ownership to another group • chown – change ownership of a file (can only be done by the superuser Above commands all support –R for recursion.
Environment List • Each process has an environment list, which is a set of environment variables maintained in the process’s user space memory. • Each list element consists of a name and an associated value • Type the printenv command to see the environment list for your login shell
Setting Environment Variables • bash export MYVAR=‘Hello world’ • tcsh setenv MYVAR ‘Hello world’ • The environment list can be inherited by a child process from the parent.
Environment Variables used by the Shell • HOME – pathname of the user’s login directory • PATH – list of directories that the shell should search for programs corresponding to commands entered by the user • To append or prepend to the PATH variable • bash: export PATH=$PATH:/path/to/dir1:/path/to/dir2 export PATH=/path/to/dir1:$PATH:/path/to/dir2 • tcsh: set PATH = ($PATH /path/to/dir1 /path/to/dir2) set PATH = (/path/to/dir1 $PATH /path/to/dir2) • Type the which command to see the complete path the shell is using for a program
I/O Redirection • Standard output • When you issue a Unix command like date, the output of the command goes to what is called standard output. $ date Thu Aug2917:10:31EDT 2013 • In Unix, you can redirect standard output to go to a file. $ date >date.txt $ cat date.txt Thu Aug2917:12:25 EDT 2013
I/O Redirection (2) • The >> symbol appends what would go to standard output to a file. $ date >>date.txt $ cat date.txt Thu Aug2917:12:25 EDT 2013 Thu Aug2917:15:10 EDT 2013 • Redirection of standard input works similarly – eg., mail -s "unix-lab1” svmoore@utep.edu < date.txt (This example may not work on all Unix systems).
Pipes • The symbol | is the Unix pipe symbol. • It means is that the standard output of the command to the left of the pipe gets sent as standard input of the command to the right of the pipe. $ cat date.txt | wc 2 12 58 Quiz question: How many processes are involved in executing the above pipeline?
Job Control • Available in all shells except Bourne shell • Allows a user to simultaneously execute and manipulate multiple commands or pipelines. • All the processes in a pipeline are placed into a new process group, or job. • A session is a collection of jobs. The session leader is the process that created the session. • All the jobs created by a job-control shell belong to the same session as the shell, which is the session leader.
Job Control (2) • Sessions usually have a controlling terminal. • At any point in time, one job in a session is the foreground job, which can read input from the terminal and send output to it. • If the user types the interrupt character (usually Control-C), or the suspend character (usually Control-Z) on the controlling terminal, the terminal driver sends a signal that kills, or suspends, the foreground job. • A session can have any number of background jobs, which are created by ending a command with &. • Useful commands: ps, bg, fg
Time • Real time is measured from some standard point (calendar time) or from the start of the life of a process (elapsed or wallclock time) • Process time, also called CPU time, is the toal amount of CPU time that a process has used since starting. • CPU time is further divided into system time (the time spent in kernel mode) and user time (the time spent in user mode)