Operating Systems 2026F Lecture 10
Video
Video from the lectures given on October 15th and 16th, 2026 are now available:
Notes
Lecture 10A
Lecture 10A
-----------
What's going to be on the midterm?
- Assignment 1 & 2
- parts of T1-4 related to A1 & A2
Concepts
- environment variables
- how to set them
- how to retrieve values
- how they are passed to other processes/programs
- getenv()/setenv()
- how shells parse commands & arguments
- how system() works
- assembly language
- compiler/assembler directives
(metadata about code)
- (high level) how functions work in assembly
- start with manipulating the stack
(save registers/allocate local variables)
- end with a ret instruction
- how C symbols show up in assembly
(function names and variables)
- how C constants show up in assembly
- especially strings
- if/while/for turn into branches (jmp, jne, etc)
- how the compiler will replace some library calls
with other calls (puts for printf)
- system calls vs function calls in assembly
(call vs syscall)
- you can't make system calls directly from C,
must use assembly/special compiler directives
- fork()
- duplicates the process
- returns "twice"
- parent & child return values
- execve()
- replaces currently running executable
- does NOT create a new process
- command line arguments
- how to make command line arguments
- how they are formatted/arranged in memory
- where they are in memory
- environment variables
- how to set/change them
- where they are in memory
- how they are arranged in memory
- how to get them
(arguments to main, extern var, getenv() )
- background vs foreground processes
- how open files can be shared between processes
- including open terminals (e.g., /dev/pts/0)
- I/O redirection
- how to change stdin, stdout, stderr for a process
(file descriptors 0, 1, 2)
- file descriptors!
- system calls, including wait and read, can fail/
return with no result
- always should check whether system calls
succeeded or not
- PATH environment variable, how used by shells
to map commands onto executables
- signals!
- how to send them
- how to define signal handlers
- how to tell the kernel to use a signal handler
- interaction with system calls
- restarting system calls
- /proc
- how it stores info about all running processes
- how to access values by reading files
- kind of info that is in those files
- relationship with ps, top
- accounts in UNIX
- what makes up an account
- entries in passwd, group, shadow, gshadow
- home directory
- accessing account info with getpwnam() and related
functions
- password hashing, keeping passwords in /etc/shadow
- and why
- root vs regular users
- setuid, dropping privileges
- user vs group vs other permissions
- users having their own shell
- how to find out what that shell is
- how to change it
Lecture 10B
Lecture 10B
-----------
To review for the midterm, we're going to make up questions for the midterm.
A1Q1
Environment variables
- What is an environment variable?
- What environment variable was used in 3000menu to create a custom command?
- either need to include 3000menu code
- or this is a test of memorization
- what's the difference between envp and environ?
- Another student was trying to set a custom command in 3000menu, but it wasn't working for them. This is the command they used:
MENUCMD="nano"
Another student says "Dummy you defined a shell variable!" What did the second student mean, and what did the first do wrong? Why wouldn't a shell variable work?
A1Q2 & A1Q8
- calling system(), which calls /bin/sh -c to execute the command
- there's a fork/execve in there, but it isn't of the
command directly
Possible questions
- What does system() do?
- What system calls does system() make?
- this is a bit tricky because it makes more than
fork/execve/wait
- 3000menu and 3000menu2 use different ways of handling commands with arguments. Which method do you think is more efficient? Why?
I/O redirection
- what is file descriptor 1 normally referred to in C?
- when a program first opens a file (using open() or other function that calls open()), it normally gets file descriptor 3 first. Why?