Chapter 3: Processes Flashcards

(303 cards)

1
Q

What limitation did early computers have regarding program execution?

A

Early computers allowed only one program to be executed at a time.

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

In early computer systems, the single running program had complete control of the system and access to all its _____.

A

resources

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

How do modern computer systems handle multiple programs compared to early systems?

A

Modern systems allow multiple programs to be loaded into memory and executed concurrently.

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

What is the formal definition of a process?

A

A process is a program in execution.

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

What was the historical term for a process in the early days of computing?

A

A process was called a job.

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

What is the purpose of the ‘Text Section’ in a process’s memory layout?

A

The Text Section contains the executable code.

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

What does the ‘Data Section’ of a process contain?

A

The Data Section contains global variables.

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

The ‘Heap Section’ of a process contains memory that is _____ allocated during run time.

A

dynamically

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

What is the function of the ‘Stack Section’ in a process?

A

It provides temporary data storage when functions are invoked.

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

What are some examples of data stored in the stack section of a process?

A

It contains function parameters, return addresses, and local variables.

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

Why are the sizes of the text and data sections considered fixed?

A

Their sizes do not change during program run time.

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

Which two sections of a process can shrink and grow dynamically during execution?

A

The stack and heap sections.

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

What is pushed onto the stack each time a function is called?

A

An activation record containing function parameters, local variables, and the return address.

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

When is the activation record popped from the stack?

A

The activation record is popped from the stack when control is returned from the function.

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

Under what circumstance does the heap section grow?

A

The heap grows as memory is dynamically allocated.

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

When does the heap section shrink?

A

The heap shrinks when memory is returned to the system.

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

What must the operating system ensure regarding the stack and heap sections as they grow toward each other?

A

The operating system must ensure they do not overlap.

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

In the memory layout of a C program, the data section is divided into which two sub-sections?

A

It is divided into initialized and uninitialized data sub-sections.

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

In a C program’s memory layout, what are the argc and argv parameters provided with?

A

A separate section is provided for the argc and argv parameters passed to the main() function.

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

What are the values passed from the command line to a C program called?

A

They are called command line arguments.

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

Command line arguments are important when you want to control your program from the outside instead of _____ those values inside the code.

A

hard coding

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

In C, how are command line arguments handled within the code?

A

They are handled using the main() function arguments, argc and argv.

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

How is the integer value of argc determined?

A

argc is equal to the sum of the number of command-line arguments and one.

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

What is the data type and structure of the argv[] parameter in C’s main function?

A

argv[] is an array of strings (character pointers).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
In the `argv` array, what does the element `argv[0]` point to?
`argv[0]` is a pointer to the name of the program.
26
Which elements of the `argv` array contain the actual command-line arguments provided by the user?
The elements `argv[1]` through `argv[argc-1]` contain the actual command-line arguments.
27
As a process executes, it changes its _____.
state
28
The state of a process is defined in part by what?
It is defined by the current activity of that process.
29
What is happening during the 'New' state of a process?
The process is being created.
30
What defines the 'Running' state of a process?
Instructions in the process are being executed.
31
What is the 'Waiting' state of a process?
The process is waiting for some event to occur, such as I/O completion.
32
What is the 'Ready' state of a process?
The process is waiting to be assigned to a processor.
33
What does the 'Terminated' state of a process signify?
The process has been terminated.
34
Are the names used for process states (New, Running, etc.) universal across all operating systems?
No, the state names are generic and vary across operating systems.
35
What is the name of the data structure in the OS kernel that contains information needed to manage a process?
It is called the Process Control Block (PCB).
36
What is an alternative name for a Process Control Block (PCB)?
It is also known as a Task Controlling Block (TCB).
37
Name one of the five key pieces of information stored in a Process Control Block (PCB).
Process state (e.g., running, waiting).
38
What does the 'Process number' field in a PCB represent?
It represents the Process ID.
39
What does the 'Program counter' stored in a PCB indicate?
It indicates the location of the next instruction to execute.
40
What kind of register information is stored in the PCB?
The contents of all process-related CPU registers are stored.
41
What type of CPU scheduling information is found in a PCB?
It contains the process priority and pointers to scheduling queues.
42
What memory-related information is stored in a PCB?
Memory management information, such as the memory allocated to the process.
43
What kind of 'Accounting information' is kept in a PCB?
Information such as CPU used, clock time elapsed since start, and time limits.
44
What 'I/O status information' is part of the PCB?
The I/O devices allocated to the process and a list of open files.
45
The traditional process model implies a program performs a _____ thread of execution.
single
46
What is a major limitation of a single thread of control in a word-processor program?
The user cannot simultaneously type in characters and run the spell checker.
47
To allow a process to perform more than one task at a time, most modern operating systems have extended the process concept to allow for what?
Multiple threads of execution.
48
On systems that support threads, what data structure is expanded to include information for each thread?
The Process Control Block (PCB) is expanded.
49
What is the term for the number of processes currently residing in memory?
The degree of multiprogramming.
50
What term describes a process that spends more of its time doing I/O than computations?
I/O-bound process.
51
A process that generates I/O requests infrequently and uses more of its time for computations is known as a _____.
CPU-bound process
52
To schedule processes effectively, what data structures does an OS typically maintain?
Multiple scheduling queues, such as the ready queue and wait queue.
53
What does the 'Ready queue' contain?
It contains a set of all processes residing in main memory that are ready and waiting to be executed.
54
What data structure is generally used to store the ready queue?
The ready queue is generally stored as a linked list.
55
What does the header of a ready queue contain?
The ready-queue header contains a pointer that points to the first PCB in the list.
56
What does the 'Wait queue' contain?
It contains a set of processes waiting for an event, such as I/O.
57
In a queuing diagram for process scheduling, what do the circles represent?
The circles represent the resources that serve the queues, like the CPU or I/O devices.
58
In a queuing diagram, what do the arrows indicate?
The arrows indicate the flow of processes in the system.
59
Where is a new process initially placed upon creation?
A new process is initially put in the ready queue.
60
After being allocated a CPU core, what is one possible event that could move a process to an I/O wait queue?
The process could issue an I/O request.
61
What might cause an executing process to be placed in a wait queue while awaiting another process's termination?
The process could create a new child process.
62
What could cause a process to be forcibly removed from the CPU core and put back in the ready queue?
The process could be interrupted or have its time slice expire.
63
When a process in a wait queue is ready to continue, it eventually switches from the waiting state to the _____ state.
ready
64
After a process transitions from waiting to ready, where is it placed?
It is put back in the ready queue.
65
A process continues the cycle of running and waiting until it _____.
terminates
66
What happens to a process's PCB and resources upon termination?
Its PCB and resources are deallocated.
67
Throughout its lifetime, a process migrates among the _____ and various _____.
ready queue; wait queues
68
What is the primary role of the CPU scheduler?
To select a process from the ready queue and allocate a CPU core to it.
69
To be fair and guarantee timely interaction, how often must the CPU scheduler select a new process for the CPU?
Frequently.
70
How does the behavior of an I/O-bound process help facilitate frequent CPU switching?
An I/O-bound process may execute for only a few milliseconds before waiting for an I/O request.
71
How is a CPU-bound process typically managed by the scheduler to prevent it from monopolizing the CPU?
The scheduler is likely designed to forcibly remove the CPU from it and select another process to run.
72
The CPU scheduler executes at least once every _____ milliseconds, although typically much more frequently.
100
73
What is the task of switching the CPU core from one process to another called?
A context switch.
74
A context switch requires performing a _____ of the current process and a _____ of a different process.
state save; state restore
75
When a context switch occurs, where does the kernel save the context of the old process?
The kernel saves the context of the old process in its PCB.
76
After saving the old process's context, what does the kernel do to run the new process?
It loads the saved context of the new process.
77
Why is the time spent on a context switch considered overhead?
Because the system does not do any useful work while switching.
78
Name one factor that affects the speed of a context switch.
Memory speed, the number of registers to be copied, or the existence of special instructions.
79
What is the typical time it takes for a context switch to occur?
Typically, a context switch takes several microseconds.
80
FREE CARD Doing 3.2 next
81
What must an OS provide mechanisms for, regarding processes?
An OS must provide mechanisms for process creation and process termination.
82
In process creation, the creating process is called a _____ process.
parent
83
A process created by a parent process is known as a _____ process.
child
84
When a child process creates other processes, what hierarchical structure is formed?
A tree of processes.
85
How do most operating systems like UNIX, Linux, and Windows identify each process?
They use a unique process identifier (pid), which is typically an integer.
86
Which process serves as the root for all user processes in modern Linux systems and always has a pid of 1?
The systemd process.
87
The _____ process is the first user process created when a modern Linux system boots.
systemd
88
In traditional UNIX systems, what is the name of the root process?
The init process.
89
After a system has booted, what kind of processes does the systemd process create?
It creates processes that provide additional services like web servers, print servers, and ssh servers.
90
What is one possibility for a parent process's execution after creating a child process?
The parent continues to execute concurrently with its children.
91
What is the alternative possibility for a parent process's execution after creating a child?
The parent waits until some or all of its children have terminated.
92
What is one possibility for the address space of a newly created process?
The child process is a duplicate of the parent process, having the same program and data.
93
What is the second possibility for the address space of a newly created process?
The child process has a new program loaded into itself.
94
In Unix, a child process is created by the _____ system call.
fork()
95
What does a child process consist of immediately after a fork() call?
It consists of a copy of the address space of the original (parent) process.
96
After a fork(), what is the next instruction executed by both the parent and child processes?
The instruction immediately following the fork() call.
97
What is the return code of the fork() system call for the newly created child process?
The return code is zero.
98
What value is returned to the parent process by a successful fork() system call?
The positive process identifier (pid) of the child is returned to the parent.
99
What value does the fork() system call return if it fails to create a child process?
It returns -1.
100
After a fork() call, what family of system calls does a child process typically use to load a new program?
The exec() family of system calls.
101
What is the primary function of the exec() family of system calls?
To replace the process's memory space with a new program.
102
When does a new program begin execution after a successful exec() call?
The new program will be executed immediately, starting from its first instruction.
103
After a fork(), what system call does the parent process typically issue to suspend its own execution?
The parent process typically issues a wait() system call.
104
What is the purpose of the parent process issuing a wait() system call?
To move itself into the wait queue until the termination of the child process.
105
What event causes the wait() system call in a parent process to complete?
The termination of the child process.
106
After a child process terminates and the parent's wait() call completes, what happens to the parent process?
The parent process resumes its execution.
107
In the GNU C library, the `pid_t` type is typically implemented as what standard data type?
It is implemented as 'int'.
108
What is the typical value range for a process ID (pid)?
A pid is normally non-negative.
109
What happens to the child process's memory space if an execlp() call is successful?
The child process is replaced by the binary executable of the new program (e.g., 'ls').
110
What value does the execlp() system call return if it leads to an error?
It returns -1.
111
When calling wait(&wait_status), what information is assigned to the `wait_status` variable?
The exit status of the terminated child process.
112
What is the return value of a successful wait(&wait_status) call?
It returns the process ID of the terminated child.
113
What is the return value of a wait(&wait_status) call on failure?
-1 is returned.
114
What is the return behavior of the exec() family of system calls when they are executed successfully?
They do not return a value; instead, the new program begins executing.
115
What value do system calls in the exec() family return upon failure?
They return -1.
116
In the names of exec() functions like execlp(), what does the letter 'l' indicate?
The 'l' indicates a list arrangement, meaning the function takes a series of Null-terminated arguments.
117
In the names of exec() functions like execvp(), what does the letter 'v' indicate?
The 'v' indicates an array (vector) arrangement, meaning the function uses an array of Null-terminated arguments.
118
In the names of exec() functions like execlp() or execvp(), what does the letter 'p' indicate?
The 'p' indicates that the environment variable PATH should be used to search for the executable file.
119
Under what condition is the execlp() system call most suitable to use?
It is used when the number of arguments to be passed to the new program is known in advance.
120
In an exec() call, when is the PATH environment variable ignored?
If the specified file name includes a slash character (i.e., a full pathname is provided).
121
In the argument list for execlp(), what does the first argument, `arg0`, typically correspond to?
It corresponds to the name of the executable file.
122
In the argument list for execlp(file, arg0, ..., argn, NULL), what do `arg1` through `argn` represent?
They correspond to the options or arguments for the executable program.
123
What is the purpose of the final NULL argument in an execlp() system call?
It is used to mark the end of the argument list.
124
Under what condition is the execvp() system call most suitable to use?
It is used when the number of arguments for the program to be executed is dynamic.
125
What is the `argv` parameter in an execvp() call?
It is an array of character pointers that point to NULL-terminated strings.
126
What must be the last member of the `argv` array in an execvp() call?
The last member of this array must be a NULL pointer.
127
What happens to the child process's memory space if an execvp() call is successful?
The child process is replaced by the binary executable of the specified program.
128
What value does the execvp() system call return if it leads to an error?
It returns '-1'.
129
Are the child and parent processes required to invoke exec() and wait() after a fork()?
No, they do not have to invoke exec() and wait().
130
If neither exec() nor wait() is called after a fork(), what is the execution flow?
Both the parent and child processes will continue to be executed from the instruction right after the fork().
131
In a program with a `printf("Hello")` statement before a `fork()` call, how many times will "Hello" be displayed?
"Hello" will be displayed once.
132
In a program with a `printf("bye")` statement after a `fork()` call, how many times will "bye" be displayed?
"bye" will be displayed two times.
133
Invoking fork() two times sequentially will result in how many child processes?
It will result in 2 child processes.
134
Invoking fork() two times sequentially will result in how many grandchild processes?
It will result in 1 grandchild process.
135
In total, how many processes (including the original) will exist after a program invokes fork() two times?
The program will result in a total of 4 processes.
136
How can the creation of grandchild processes be prevented when using fork() inside a loop?
By having each child process invoke exit() to terminate itself before the next iteration of the loop.
137
What does the macro `WIFEXITED(status)` return if a child process terminated normally?
It returns true.
138
If a child process inside a loop calls exit() after its creation, and the parent waits, how many grandchild processes are created?
No grandchild processes are created.
139
What is one way a process can terminate naturally?
A process terminates when all of its instructions have been executed.
140
What system call can a process invoke to terminate itself explicitly?
The process can invoke the exit() system call.
141
What happens to a process's resources when exit() is invoked?
All resources, including memory, open files, and I/O buffers, are deallocated and reclaimed by the OS.
142
What does a zero exit status typically signify?
A zero exit status means the execution was successful.
143
A non-zero exit status (ranging from 1 to 255) typically signifies what?
It means the execution led to a failure.
144
What system call allows one process to cause the termination of another process?
An appropriate system call, such as kill().
145
Who can typically invoke a system call like kill() to terminate a specific process?
Usually, it can only be invoked by the parent of the process that is to be terminated.
146
What must a parent process know in order to terminate one of its children?
The parent needs to know the identity (e.g., pid) of its children.
147
How does a parent process learn the identity of a newly created child process?
The identity of the newly created process is passed to the parent (as the return value of fork()).
148
When a parent waits for a child, its state changes and it is moved into the _____.
wait queue
149
When a child process overlays its address space with `execlp("ls", "ls", "-l", NULL)`, it is replaced by the binary executable of ____.
ls
150
When `execlp()` is called with `"/usr/bin/ls"`, what is the effect on the PATH environment variable?
The PATH variable is ignored, and the file at the specified pathname is executed.
151
A process can be terminated when it finishes all its instructions or when it invokes the _____ system call.
exit()
152
A process can cause the termination of another process using a system call like _____.
kill()
153
The system call `fork()` creates a new child process by creating a _____ of the address space of the parent process.
copy
154
The `wait()` system call returns the _____ of the terminated child on success.
process ID
155
After a `fork()`, the parent process can either continue to execute _____ with its children or wait for them to terminate.
concurrently
156
FREE CARD Doing 3.3 next
157
What is the definition of an 'independent' process?
A process is independent if it does not share data with any other processes executing in the system.
158
What is the definition of a 'cooperating' process?
A process is cooperating if it can affect or be affected by other processes executing in the system.
159
What is one reason for providing an environment that allows process cooperation?
Information sharing among processes.
160
How can process cooperation lead to a 'computation speedup'?
A task can be broken into subtasks, which can then be executed in parallel by separate processes.
161
How does process cooperation support 'modularity' in system design?
It allows system functions to be divided into separate processes or threads.
162
Cooperating processes require an _____ mechanism to allow them to exchange data.
interprocess communication (IPC)
163
What are the two fundamental models for interprocess communication (IPC)?
Shared memory and message passing.
164
In shared-memory IPC, what must communicating processes first establish?
A region of shared memory.
165
Where does a shared-memory region typically reside?
In the address space of the process that created the shared-memory segment.
166
How does a process, other than the creator, gain access to a shared-memory segment?
It must attach the shared-memory segment to its own address space.
167
What is the producer-consumer problem a common paradigm for?
Cooperating processes.
168
In the producer-consumer problem, what is the role of the 'producer' process?
It produces information that is consumed by another process.
169
In the producer-consumer problem, what is the role of the 'consumer' process?
It consumes information that is produced by another process.
170
To allow producer and consumer processes to run concurrently using shared memory, what data structure is needed?
A buffer that can be filled by the producer and emptied by the consumer.
171
What is an 'unbounded buffer' in the context of shared-memory IPC?
A buffer that places no practical limit on its size.
172
With an unbounded buffer, under what condition must the consumer wait?
The consumer may have to wait for new items if the buffer is empty.
173
What is a 'bounded buffer' in the context of shared-memory IPC?
A buffer that assumes a fixed size.
174
With a bounded buffer, when must the consumer wait?
The consumer must wait if the buffer is empty.
175
With a bounded buffer, when must the producer wait?
The producer must wait if the buffer is full.
176
In the shared-memory implementation of a bounded buffer, what data structure is the buffer commonly implemented as?
A circular array.
177
In the shared-memory bounded buffer example, what does the `in` pointer indicate?
The `in` pointer points to the next free position in the buffer.
178
In the shared-memory bounded buffer example, what does the `out` pointer indicate?
The `out` pointer points to the first full position in the buffer.
179
In the shared-memory bounded buffer example, what is the condition for the buffer being empty?
The buffer is empty when `in == out`.
180
In the shared-memory bounded buffer example, what is the condition for the buffer being full?
The buffer is full when `((in + 1) % BUFFER_SIZE) == out`.
181
In the producer process code for shared memory, what is the purpose of the `next_produced` variable?
It is a local variable where the new item to be produced is stored before being placed in the buffer.
182
What condition does the producer process loop on while waiting for space in the shared buffer?
`while (((in + 1) % BUFFER_SIZE) == out)`
183
What C code statement does the producer use to add an item to the shared buffer?
`buffer[in] = next_produced;`
184
How does the producer process update the `in` pointer after adding an item to the shared buffer?
`in = (in + 1) % BUFFER_SIZE;`
185
In the consumer process code for shared memory, what is the purpose of the `next_consumed` variable?
It is a local variable where the item retrieved from the buffer is stored.
186
What condition does the consumer process loop on while waiting for an item in the shared buffer?
`while (in == out)`
187
What C code statement does the consumer use to retrieve an item from the shared buffer?
`next_consumed = buffer[out];`
188
How does the consumer process update the `out` pointer after retrieving an item from the shared buffer?
`out = (out + 1) % BUFFER_SIZE;`
189
In the given producer-consumer shared-memory scheme, what is the maximum number of items allowed in the buffer?
At most `BUFFER_SIZE - 1` items.
190
What key problem regarding shared memory access is NOT solved by the simple producer-consumer example?
The problem of concurrent memory access, or race conditions.
191
Besides sharing a memory region, what is another requirement of the shared-memory IPC scheme for the programmer?
The code for accessing and manipulating the shared memory must be written explicitly by the application programmer.
192
What mechanism does an OS provide as an alternative to shared-memory IPC?
A message-passing facility.
193
What does message passing allow processes to do without sharing the same memory region?
It allows them to communicate and synchronize their actions.
194
In which type of computing environment is message passing particularly useful?
In a distributed environment, where processes may reside on different computers.
195
A message-passing facility provides at least which two operations?
`send(message)` and `receive(message)`.
196
For two processes P and Q to communicate via message passing, what must exist between them?
A communication link.
197
In message passing, what is 'direct communication'?
A communication method where each process must explicitly name the recipient or sender.
198
Under direct communication, what is the primitive to send a message to process X?
`send(X, message)`
199
Under direct communication, what is the primitive to receive a message from process X?
`receive(X, message)`
200
What is a property of a communication link in a direct communication scheme?
A link is associated with exactly two processes.
201
In a direct communication scheme, how many links exist between each pair of processes?
Exactly one link.
202
In message passing, what is 'indirect communication'?
A communication method where messages are sent to and received from mailboxes, or ports.
203
In indirect communication, a _____ can be viewed as an object into which messages can be placed and from which they can be removed.
mailbox
204
Under indirect communication, what is the primitive to send a message to mailbox A?
`send(A, message)`
205
Under indirect communication, what is the primitive to receive a message from mailbox A?
`receive(A, message)`
206
In indirect communication, how is a link established between a pair of processes?
A link is established only if both processes have a shared mailbox.
207
How many processes can be associated with a single mailbox in indirect communication?
A mailbox may be associated with more than two processes.
208
Blocking message passing is also known as _____ communication.
synchronous
209
Nonblocking message passing is also known as _____ communication.
asynchronous
210
Term: Blocking send
The sending process is blocked until the message is received by the receiving process or by the mailbox.
211
Term: Nonblocking send
The sending process sends the message and resumes other operations without waiting.
212
Term: Blocking receive
The receiver is blocked until a message is available.
213
Term: Nonblocking receive
The receiver is not blocked while it waits for a message; it can periodically check for one.
214
How does the producer-consumer problem become trivial using message passing?
By using blocking `send()` and blocking `receive()` statements.
215
In message passing, where do messages exchanged by communicating processes reside temporarily?
In a temporary queue.
216
What does a 'zero capacity' buffer in message passing mean?
The queue has a maximum length of zero, meaning the sender must block until the receiver is ready.
217
What is another name for a message system with a zero-capacity queue?
A message system with no buffering.
218
What does a 'bounded capacity' buffer in message passing mean?
The queue has a finite length n, and at most n messages can reside in it.
219
What does an 'unbounded capacity' buffer in message passing mean?
The queue's length is potentially infinite, so the sender never needs to block.
220
Message systems with bounded or unbounded capacity are referred to as systems with _____.
automatic buffering
221
What is the role of system calls in establishing a shared-memory region?
A process issues a system call to request that the kernel make a region of its memory shared.
222
After a shared-memory region is established, how are subsequent accesses to it handled?
They are treated as routine memory accesses, with no further assistance from the kernel required.
223
In message passing, what must a process do to exchange a piece of data?
It must invoke the kernel with a system call to request the data be transferred.
224
What is the kernel's role when a `send` operation is invoked in message passing?
The kernel copies the transferred data first into its own memory.
225
In message passing, the kernel is involved in every _____ exchange of data.
distinct
226
Why is shared-memory IPC generally faster than message-passing IPC?
Because system calls are only required to establish the shared region, not for every data access.
227
Why is message-passing IPC generally slower than shared-memory IPC?
Because it is implemented using system calls, which require more time-consuming kernel intervention for every exchange.
228
Which IPC model typically requires more explicit involvement from the application programmer?
Shared memory, as the programmer must write the code for accessing and manipulating the shared region.
229
Which IPC model is generally less suitable for a distributed environment?
Shared memory, because it is difficult to share a memory section across different computers connected by a network.
230
Which IPC model is generally more suitable for a distributed environment?
Message passing.
231
FREE CARD Doing 3.4 now
232
What are the two example IPC methods covered for POSIX systems?
POSIX Shared Memory (shared memory) and Pipe/FIFO (message passing).
233
In POSIX, shared memory is implemented using a memory-_____ file.
mapped
234
What is the first step a process must take to use POSIX shared memory?
It must create a shared-memory object using the shm_open() system call.
235
Essentially, what is a POSIX shared-memory object?
A file that will be mapped to a memory section.
236
What system call is used to create a new shared-memory object or open an existing one?
The shm_open() system call.
237
In `shm_open(name, O_CREAT | O_RDWR, 0666)`, what does the first parameter (`name`) specify?
The name of the shared-memory object, which other processes use to access it.
238
In `shm_open()`, what is the purpose of the `O_CREAT` flag?
It indicates that the shared-memory object should be created if it does not yet exist.
239
In `shm_open()`, what is the purpose of the `O_RDWR` flag?
It indicates that the object is open for both reading and writing.
240
What does a successful call to `shm_open()` return?
An integer file descriptor for the shared-memory object.
241
In `shm_open()`, what does the last parameter, such as `0666`, specify?
The access permissions of the new file corresponding to the created object.
242
What do the file permissions `0666` mean?
Read and write access for the owner, group, and other users.
243
What is the second step in using POSIX shared memory, after the object is established?
To configure the size of the object in bytes using the ftruncate() function.
244
Which function is used to set the size of a shared-memory object?
The ftruncate() function.
245
What is the third step in using POSIX shared memory, after setting its size?
To map the object to a memory section using the mmap() function.
246
What is the main purpose of the `mmap()` function in the context of shared memory?
It maps a file to a memory section so that direct file operations are not needed.
247
What does the `mmap()` function return after successfully mapping an object?
A pointer that is used for accessing the shared-memory object.
248
In the producer-consumer problem using POSIX shared memory, what is the role of the producer?
The producer establishes a shared-memory object and writes to shared memory.
249
In the producer-consumer problem using POSIX shared memory, what is the role of the consumer?
The consumer reads from shared memory.
250
In `mmap()`, what does the protection flag `PROT_WRITE` signify?
It signifies that the mapped memory region may be written to.
251
In `mmap()`, what does the `MAP_SHARED` flag indicate?
It indicates that updates to the mapping are visible to other processes sharing the same object.
252
The `strlen()` function returns the length of a string, excluding the _____ character at the end.
NULL
253
What is the most portable method for creating a new mapping with `mmap()`?
Setting the first parameter (the address) to 0, which lets the kernel choose the address.
254
In `mmap()`, what does setting the offset parameter to 0 signify?
The start of the file corresponds to the start of the memory object.
255
In `mmap()`, what does the protection flag `PROT_READ` signify?
It signifies that the mapped memory region may be read from.
256
Which function is used to remove a POSIX shared memory object from the system?
The shm_unlink() function.
257
In the producer-consumer example, why can a single `printf()` display two messages that were written separately?
The NULL character of the first message was overwritten, combining the two C strings into one.
258
When compiling POSIX shared memory programs, what flag must be added to link the realtime extensions library?
The "-lrt" flag.
259
What is the GCC command to compile a POSIX producer program named 'shm-posix-producer.c' into an executable named 'producer'?
gcc -o producer shm-posix-producer.c -lrt
260
After a POSIX producer program is executed, where is the file corresponding to the shared memory object typically placed?
In the /dev/shm directory.
261
What happens to the shared memory file in /dev/shm after the consumer process invokes `shm_unlink()`?
The file is removed and disappears from the directory.
262
Does POSIX Shared Memory work between a parent process and a child process created by `fork()`?
Yes, the shared memory remains accessible and shared between them.
263
Why is `strncpy()` considered a safer alternative to `strcpy()`?
It allows specifying a maximum number of bytes to copy, which helps prevent buffer overflows.
264
When using `strncpy(dest, src, n)`, what happens if the source string `src` is shorter than `n` bytes?
The remaining part of the destination buffer `dest` is padded with null characters ('\0').
265
When using `strncpy(dest, src, n)`, what is a critical consideration if the source string `src` is longer than `n` bytes?
The destination string `dest` is not automatically null-terminated.
266
The operation of `shm_open()` is analogous to that of which other standard system call?
The `open()` system call.
267
Pipes were one of the first IPC mechanisms in early _____ systems.
UNIX
268
Overall, a pipe belongs to which category of Interprocess Communication (IPC)?
Message-passing.
269
What is one of the four key issues to consider for a pipe implementation concerning communication direction?
Whether the pipe allows bidirectional communication or is only unidirectional.
270
If a pipe allows two-way communication, what is the second design issue to consider?
Whether it is half duplex (one way at a time) or full duplex (both ways at the same time).
271
What is the third design issue for pipes, regarding the relationship between processes?
Whether a special relationship (such as parent–child) must exist between them.
272
What is the fourth design issue for pipes, concerning their location?
Whether they can communicate over a network or only on the same machine.
273
What are the two common types of pipes used on UNIX systems?
Ordinary pipes and named pipes.
274
How do ordinary pipes facilitate communication between two processes?
In a standard producer–consumer fashion.
275
In an ordinary pipe, the producer writes to the _____ end.
write
276
In an ordinary pipe, the consumer reads from the _____ end.
read
277
Are ordinary pipes unidirectional or bidirectional?
They are unidirectional, allowing only one-way communication.
278
If two-way communication is required using ordinary pipes, what must be done?
Two separate pipes must be used, with each sending data in a different direction.
279
On UNIX systems, what function is used to construct an ordinary pipe?
The `pipe(int fd[])` function.
280
When a pipe is created with `pipe(int fd[])`, what does the file descriptor `fd[0]` represent?
The read end of the pipe.
281
When a pipe is created with `pipe(int fd[])`, what does the file descriptor `fd[1]` represent?
The write end of the pipe.
282
UNIX treats a pipe as a special type of file, allowing it to be accessed with which two ordinary system calls?
The `read()` and `write()` system calls.
283
What kind of relationship is typically required for processes to communicate using an ordinary pipe?
A parent-child relationship.
284
How do a parent and child process communicate using an ordinary pipe after a `fork()` call?
The file descriptors for the pipe are shared between them, allowing them both to access it.
285
What is the buffer size of a pipe in Linux systems since version 2.6.11?
65,536 bytes.
286
What happens if a process attempts to `write()` to an ordinary pipe that is full?
The `write()` operation will block or fail.
287
What is an important practice for both the parent and child process after a pipe is created and the child is forked?
Each process should close its unused end of the pipe.
288
Does the concept of half duplex or full duplex apply to a single ordinary pipe?
No, because ordinary pipes are strictly unidirectional.
289
Can ordinary pipes be used for communication between processes residing on different machines?
No, the communicating processes must reside on the same machine.
290
What is a major limitation of ordinary pipes regarding their lifespan?
They do not continue to exist after the communicating processes have terminated.
291
Unlike ordinary pipes, named pipes _____ after communicating processes have terminated.
continue to exist
292
Are named pipes capable of bidirectional communication?
Yes, they are.
293
Is a parent-child relationship required for processes to communicate using named pipes?
No, a parent-child relationship is not required.
294
On UNIX, can named pipes be used by communicating processes on different machines?
No, the processes must reside on the same machine.
295
In UNIX systems, what are named pipes commonly referred to as?
FIFOs (First-In, First-Out).
296
Once created, how do FIFOs (named pipes) appear in a UNIX system?
They appear as regular files in the file system.
297
What system call is used to create a FIFO in UNIX?
The `mkfifo()` system call.
298
After being created with `mkfifo()`, a FIFO can be manipulated with which ordinary system calls?
The `open()`, `read()`, `write()`, and `close()` system calls.
299
How long does a FIFO (named pipe) persist on the file system?
It continues to exist until it is explicitly deleted.
300
Although FIFOs on UNIX allow bidirectional communication, what type of transmission is actually permitted?
Only half-duplex transmission is permitted.
301
On UNIX, if data must travel in both directions simultaneously, how is this typically achieved with FIFOs?
Two FIFOs are used, one for each direction of data flow.
302
How does the Microsoft Windows version of a named pipe differ from the UNIX version in terms of duplex capability?
The Windows version allows for full-duplex communication.
303
How does the Microsoft Windows version of a named pipe differ from the UNIX version in terms of process location?
The Windows version allows communicating processes to be on the same or different machines.