SRE Questions Flashcards
What is the difference between a process and a thread?
- Thread is a light weight process
- threads have their own stack, but share these with the parent process
- text (program code)
- data (program input)
- heap (stores files, locks, sockets)
What is a zombie process?
- has completed execution
- still in the process table so the parent can read the child’s exit status
- it’s dead, but not yet reaped by it’s parent
- when a parent makes a system call to read the exit status, then the process is removed
- kill doesn’t work on zombie processes
- don’t take up system resources
How to get rid of a zombie process?
- killing the parent should work to eliminate a zombie. (pid 1 will own it and then kill it)
How do you end up with zombie processes?
- created if the parent process doesn’t reap the child
- can happen if the parent doesn’t execute the wait() system call after forking
How does the system daemonize a process?
The fork() call is used to create a separate process.
The setsid() call is used to detach the process from the parent (normally a shell).
The file mask should be reset. The reason for this is because we want to create new files with the mask that is needed for the child process.
The current directory should be changed to something benign. We may not want the child to be in the same pwd as the parent.
The standard files (stdin,stdout and stderr) need to be reopened.
Describe ways of process inter-communication
Shared memory - threads share memory inside a process
POSIX mmap - a system call that maps files or devices into memory
Message queues - they allow multiple processes to read/write to the message queue without being directly connected
socket - sends streaming data over a network interface
pipes - these direct input/output of one process to another
Unix domain sockets - similar to an internet socket, but all communication occurs within the kernel. Use the file system as their address space.
RPC - remote procedure call
File - multiple processes can read/write
http://en.wikipedia.org/wiki/Inter-process_communication
What is a system call that maps files or devices into memory? _____ _____
POSIX mmap
Does the OS have message queues?
Yes - they allow multiple processes to read/write to the message queue without being directly connected
____ sends streaming data over a network interface
socket - sends streaming data over a network interface
What does a Unix domain socket do?
They are similar to an internet socket, but all communication occurs within the kernel. Use the file system as their address space.
___ ___ ___ is when a computer program causes a procedure to execute in a different address space (this computer or another computer over a network) which is coded as if it were a normal procedure call without the programmer explicitly coding the details for the remote interaction.
It is also a form of inter-process communication, in that different processes have different address spaces: if on the same host machine, they have distinct virtual address spaces, even though the physical address space is the same; while if they are on different hosts, the physical address space is different.
RPC - remote procedure call
https://en.wikipedia.org/wiki/Remote_procedure_call
Describe how processes executes in a Unix shell
Example /bin/ls
- when you run ‘ls’
- the shell searches the path for an executable named ls
- the shell process forks off a copy of itself
- if the fork succeeds, then it will run the full executable path it found with ‘exec /bin/ls’.
This replaces the copy of the child shell with itself. Parameters passed in are also run by exec.
What are unix signals?
Signals are a way the OS communicates with processes.
The ‘kill’ command is used to send signals to a process.
Example signals:
SIGTERM 15 (optional - default signal to send with kill)
SIGINT 2 Term Interrupt from keyboard
SIGQUIT 3 Core Quit from keyboard
SIGKILL 9 Term Kill signal (not optional)
SIGSTOP 17,19,23 Stop Stop process
SIGPIPE 13 Term Broken pipe: write to pipe with no
readers
The signals SIGKILL and SIGSTOP cannot be caught, blocked, or
ignored.
What does ‘echo $?’ tell you?
This is the exit code from the last run process
When you send a HUP signal to a process, you notice that it has no impact, what could have happened?
During critical section execution, some processes can setup signal blocking. The system call to mask signals is ‘sigprocmask’. When the kernel raises a blocked signal, it is not delivered.
Such signals are called pending. When a pending signal is unblocked, the kernel passes it off to the process to handle. It is possible that the process was masking SIGHUP.