Process Environment Flashcards

1
Q

What is a process and how does the OS simulate parallel processing?

A

A process is a program in execution.

The OS runs processes concurrently by interleaving their execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the different components of the process state?

A
  • Unique ID
  • Private address space
    • stack
    • heap
    • code and data
  • Registers for context switching
  • Resources
    • Files
    • Sockets
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you get the processID and what are the header files needed for this?

A

include <sys></sys>

The header files needed for this are:

You get the process ID by using the getpid() function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens when a parent creates a child process using the fork function?

A

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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why does fork return twice?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens when the parent terminates before the child?

A

When the parent terminates before the child, then the child is assigned to ( or rather adopted lol ) by the init process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does the parent know when a child has terminated? ( without waiting )

A

The parent is notified by the kernel through an asynchronous message known as a signal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What happens when you call wait inside a parent?

A

The parent blocks until a child has been terminated.

If there are no children, then wait returns immediately.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a zombie process?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What happens when a process is a zombie process?

A
  • It remains in the process table
  • Its memory and resources are de-allocated
  • It can be reaped, when the parent waits on it.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why should you be worried about zombie processes?

A

Too many zombie processes prevent the creation of new processes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the different exit functions to terminate a program?

What does atexit do and what is its prototype?

A

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))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

atexit adds exit handlers to a stack of exit handlers, what does this mean for the order of registering exit handlers?

A

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) .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are environment variables?

A

These are key value pairs defined in the command shell.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the prototype of getenv and what does it do?

A

char* getenv(char* varname):

This function gets the value of the variable with name varname

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which component is responsible for including libraries inside a program?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a static library?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are Shared or dynamic Libraries?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is dynamic linking?

A

Link to the libraries during runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Describe a process’ address space.

A

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.
21
Q

how does the size of the address space depend on the architecture?

Are all addresses in this range accessible?

A

2^(the number of bits)

16 bit System = 2^16

32 bit System = 2^32

Not all addresses in this range are accessible

22
Q

what is kernel space and how is it different from user space?

A

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.

23
Q

how is a process divided in terms of memory?

A

A process is divided into memory segments.

24
Q
  1. Each process has its own address space
  2. The total of all virtual addresses is greater than the physical memory
  3. Virtual address is actually disconnected from physical memory
  4. Each signal is identified by a unique integer value
  5. You can send signals from the terminal using the kill command.
    1. kill -;

    2. 6.
A
25
Q

What are the consequences or process separation?

A
  1. One process can’t peek into another process’ data
  2. it is difficult to transfer any piece of data from one process to another.
26
Q

how many cpu rings are there and what is ring 0 and ring 3 used for?

A

There are 4 cpu rings.

RIng 0: Kernel space has this, this has full access including the physical memory and it can edit page tables

Ring 3: ( User space has this ring ), this ring has indirect access to memory via page tables, cannot edit the page tables and also does not have permissions for some CPU instructions.

27
Q

Why does the OS set a timer interrupt before giving up control to the user processes?

A

This is because the user processes cannot be trusted to restore control back to the OS.

28
Q

What are system calls?

What are some resources that are requested?

A

These are programmatic means of requesting privileged resources.

Some resources are:

  • Communication
  • File management
  • Process control
29
Q

When are memory faults or segfaults encountered?

A

They are encountered when the process reads a memory address that is invalid or not currently mapped in the page table

30
Q

How do you make a page shareable with other processes and give an example where page sharing is used?

A

In order to make pages shareable, you need to make them read only.

Read only pages can be shared among processes without any risk.

They are used for shared libraries.

31
Q

What system call do you use in order to replace the current program with a new program.

A

The family of exec functions can be used for this.

32
Q

What happens to the process ID when you call the exec function, what happens ot the stack, heap and so on…?

A

The process ID is retained but the stack, heap and data are cleared

Any open file descriptors are retained

33
Q

What is the prototype of the exec function and describe the usage, what does it return?

A

int execv(char* path, char* argsv[])

path: The name of the executable file
argsv: the argument list that is passed to the main function.

  • The first argument should be the name of the exe
  • The last argument should be null

Exec functions return on failure, or the just replace the current program with tne new program

34
Q

What is the copy on write feature and why is it even used?

A

Copy on write feature is basically making the parent and the child ( created after forking ) share the same address space. The pages of the parent will only be copied and given to the child if there is any attempt to write by the child.

It is used because, usually the child does not change many of the pages so it is a waste copy all of these pages

35
Q

What is overcommitting?

A

When the OS promises more memory the processes than it has physically

36
Q

What are half duplex pipes?

A

Half duplex pipes are data channel that allow one way communication between a parent and a child.

37
Q

How do you create a pipe and what is the prototype?

A

Prot: int pipe ( int fd[2] );

fd[0] and fd [1] are the 2 endpoints of the pipes.

38
Q

What are signals?

A

Signals are asynchronous messages that are sent to the program to notify it that some event has occurred.

39
Q

Whar are async signal safe functions?

A

Signal safe functions are those that can be safely called from within a signal handler.

40
Q

What are the three types of signals and give examples for these.

A

The three types of signals are

  • Errors:
    • SIGSEGV
    • SIGINT
  • Notification
    • SIGALRM
    • SIGCHLD
  • Process Control
    • SIGKILL
    • SIGSTOP
41
Q

What are the different ways in which a process can behave when it receives a signal?

A

When a process receives a signal, it can behave one out of 4 ways

  • Terminate the program
  • Stop the program
  • Terminate the program and make a core dump
  • Ignore it.
42
Q

How do you send a signal to the same process, also mention the header file needed for this?( Prototype?)

A

You send a signal to the same process by using the raise function.

int raise(int sig);

The header file for this is

43
Q

How do you send a singal to a different process?

A

In order to send a signal to a different process, use the kill function.

int kill(pid_t process, int sig)

44
Q

What are some of the control commands that send the singals to foreground processes ( processes that are currently running )

A

They are:

  • ctri-c:
  • ctrl-z:
  • ctrl-:
45
Q

How do you registe a signal handler?

A

you register a signal handler by using the signal function.

signal(int signum, singnalhandler):

NOTE: signal is deprecated and now the sigaction is used instead

46
Q
A
47
Q

Which are the 2 signals that cannot be handled or ignored?

A

sigkill and sigstop

48
Q

What are some built in signal handlers for

  • ignoring a signal
  • default handler for a signal
A

To ignore the signal: SIG_IGN

Default handler: SIG_DFL