1/49
Looks like no tags are added yet.

Globals are automatically initialized to zero
True

BSS is where static variables are located
True

Name the four segments of the memory model:
Text (code), static/data (incl. BSS), heap, stack

Segment holding machine instructions?
Text (code)

Where dynamic allocation happens
Heap

Segment saving return address and arguments on each call:
Stack

Segment whose items last until the program deletes them or ends
Heap

Postfix i++ on a variable used elsewhere in the same expression:
Undefined behavior

Standard file descriptors open at start
stdin, stdout, stderr

fopen(filename, mode)
Opens the file in the given mode ("r", "w", "a", plus "+" variants) and returns NULL on failure

Differences between parent and child:
Different PIDs, different fork return value, separate copies of memory
fork's return value in the child:
0
fork's return value on failure:
-1
Processes after one fork
2

if (fork()) cout...
Prints 1 time
Displays a zero getpid() after a fork
False (getpid never returns 0)

Loop for (i = 1; i < n; i++) fork()
2^(n−1) processes
Which is NOT true about forks
Pick the choice claiming shared memory or the same PID
Example: "the child shares the parent's variables" is false because the child gets a copy. "The child has the same PID" is also false.
True statements: the child inherits open file descriptors and a copy of memory.
Parent's PID is always zero after a fork
False

if (fork()) fork(); fork(); if (fork()) fork()
18 processes
What dup does:
Duplicates a file descriptor, returning the lowest unused one
Three forks in a row, how many processes?
8 processes

Index to read from a pipe
0

Index to write to a pipe
1
Which is NOT true about pipes
Pick the choice claiming pipes are bidirectional or connect unrelated processes
Example: "a pipe carries data both ways" is false because it is one-way. “
“Any two unrelated processes can share a pipe" is false because the pipe must be created before fork so the child inherits both ends.

Named-pipe open blocks until the other side opens
True

Client and server must use a known named pipe:
True

Order of named-pipe operations
Create the name string, mkfifo, chmod, open
execvp creates a new process mirroring the caller
False (it replaces the current process image)
What two sockets must agree on
Protocol/type, IP address, and port

Correct client socket order:
socket, connect, read/write, close
API not used in client code:
bind, listen, or accept

IPC mechanisms that work across a network
Sockets

Item not related to sockets
Pick the pipe, shared-memory, or fork-related choice
Example: socket, bind, htons, and sockaddr_in are socket-related. pipe() and mkfifo() are not.
Sockets cannot be used on the same machine
False

Server-side order
socket, bind, listen, accept, read/write
SOCK_STREAM
Reliable, connection-oriented byte stream (TCP)
Loopback IP address:
127.0.0.1
pthread_create start routine takes only one argument:
True (a single void *)
A pthread_start command is needed to start the thread
False
A process has one thread by default:
True
Building requires pthread.h and -pthread on the g++ line:
True
Segment not shared between threads:
Stack
Threads help because they can run longer than the process's allotted time
False

Critical code section
Code touching shared data that only one thread may run at a time

Lock/unlock device:
Mutex

Call that waits for a thread to finish
pthread_join
Is cout thread safe:
False
Linux is:
Preemptive and time-shared
PaaS means Programming as a Service:
False