Process Environment Flashcards
What is a process and how does the OS simulate parallel processing?
A process is a program in execution.
The OS runs processes concurrently by interleaving their execution.
What are the different components of the process state?
- Unique ID
- Private address space
- stack
- heap
- code and data
- Registers for context switching
- Resources
- Files
- Sockets
How do you get the processID and what are the header files needed for this?
include <sys></sys>
The header files needed for this are:
You get the process ID by using the getpid() function
What happens when a parent creates a child process using the fork function?
When the parent creates a child process using the fork function then the child
- Copy of the parent’s address space
- Any open files in the parent are available to the child.
Why does fork return twice?
Fork returns twice, once for the parent and once for the child.
When it returns for the parent, it returns the process of the child and when it returns for the child, it returns 0.
This can be used to distinguish the parent process from the child process.
What happens when the parent terminates before the child?
When the parent terminates before the child, then the child is assigned to ( or rather adopted lol ) by the init process.
How does the parent know when a child has terminated? ( without waiting )
The parent is notified by the kernel through an asynchronous message known as a signal.
What happens when you call wait inside a parent?
The parent blocks until a child has been terminated.
If there are no children, then wait returns immediately.
What is a zombie process?
This is a process that has finished executed but it has an entry in the process table. The process has terminated but is not waited on by the parent.
What happens when a process is a zombie process?
- It remains in the process table
- Its memory and resources are de-allocated
- It can be reaped, when the parent waits on it.
Why should you be worried about zombie processes?
Too many zombie processes prevent the creation of new processes.
What are the different exit functions to terminate a program?
What does atexit do and what is its prototype?
The different exit functions are:
- exit: Clean assassination, calls all the exit handlers
- _exit: Merciless exit, directly returns to the OS
- _Exit: same as above
- abort:
- atexit: allows you to register exit handlers that can are called during the termination of the program.
- Prototype: int atexit(void(*function)(void))
atexit adds exit handlers to a stack of exit handlers, what does this mean for the order of registering exit handlers?
This means the exit handler that you want to have executed first should be registered the last, because the last one in will be executed first (LIFO) .
What are environment variables?
These are key value pairs defined in the command shell.
What is the prototype of getenv and what does it do?
char* getenv(char* varname):
This function gets the value of the variable with name varname
Which component is responsible for including libraries inside a program?
The libraries are included inside the user code with the help of the linker file. The linker checks the set of know directories for the library.
What is a static library?
A static libraries are created when the library itself is copied and inserted into the user code. This means that any changes to the libraries requrie relinking of the library.
What are Shared or dynamic Libraries?
These are libraries that are not copied into the executable file but rather is refered to by executables.
If the libraries change then there is no need to relink.
What is dynamic linking?
Link to the libraries during runtime.
Describe a process’ address space.
Process address space is the memory that is allocated to a process by the OS
A process
- address space is Contiguous in memory
- executes in the virtual memory
- address space is known as virtual address space.
how does the size of the address space depend on the architecture?
Are all addresses in this range accessible?
2^(the number of bits)
16 bit System = 2^16
32 bit System = 2^32
Not all addresses in this range are accessible
what is kernel space and how is it different from user space?
Kernel space is the part of virtual address space where kernel processes run on.
User space is the part of the Virtual address space where the normal applications run.
The role of the kernel space is to manage applications running in the user space.
how is a process divided in terms of memory?
A process is divided into memory segments.
- Each process has its own address space
- The total of all virtual addresses is greater than the physical memory
- Virtual address is actually disconnected from physical memory
- Each signal is identified by a unique integer value
- You can send signals from the terminal using the kill command.
- kill -;
- …
6.