Scott Dollinger CS3377 Exam 2

0.0(0)
Studied by 2 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/49

encourage image

There's no tags or description

Looks like no tags are added yet.

50 Terms

1
New cards
<p>Globals are automatically initialized to zero</p><p></p>

Globals are automatically initialized to zero


True

2
New cards
<p>BSS is where static variables are located</p>

BSS is where static variables are located

True

3
New cards
<p>Name the four segments of the memory model: </p>

Name the four segments of the memory model:

Text (code), static/data (incl. BSS), heap, stack

4
New cards
<p>Segment holding machine instructions? </p>

Segment holding machine instructions?

Text (code)

5
New cards
<p>Where dynamic allocation happens</p>

Where dynamic allocation happens

Heap

6
New cards
<p>Segment saving return address and arguments on each call:</p>

Segment saving return address and arguments on each call:

Stack

7
New cards
<p>Segment whose items last until the program deletes them or ends</p>

Segment whose items last until the program deletes them or ends

Heap

8
New cards
<p>Postfix i++ on a variable used elsewhere in the same expression: </p>

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

Undefined behavior

9
New cards
<p>Standard file descriptors open at start</p>

Standard file descriptors open at start

stdin, stdout, stderr

10
New cards
<p>fopen(filename, mode)</p>

fopen(filename, mode)

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

11
New cards
<p>Differences between parent and child: </p>

Differences between parent and child:

Different PIDs, different fork return value, separate copies of memory

12
New cards

fork's return value in the child:

0

13
New cards

fork's return value on failure:

-1

14
New cards

Processes after one fork

2

15
New cards
<p>if (fork()) cout...</p>

if (fork()) cout...

Prints 1 time

16
New cards

Displays a zero getpid() after a fork

False (getpid never returns 0)

17
New cards
<p>Loop for (i = 1; i &lt; n; i++) fork()</p>

Loop for (i = 1; i < n; i++) fork()

2^(n−1) processes

18
New cards

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.

19
New cards

Parent's PID is always zero after a fork

False

20
New cards
<p>if (fork()) fork(); fork(); if (fork()) fork()</p>

if (fork()) fork(); fork(); if (fork()) fork()

18 processes

21
New cards

What dup does:

Duplicates a file descriptor, returning the lowest unused one

22
New cards

Three forks in a row, how many processes?

8 processes

23
New cards
<p>Index to read from a pipe</p>

Index to read from a pipe

0

24
New cards
<p>Index to write to a pipe</p>

Index to write to a pipe

1

25
New cards

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.

26
New cards
<p>Named-pipe open blocks until the other side opens</p>

Named-pipe open blocks until the other side opens

True

27
New cards
<p>Client and server must use a known named pipe:</p>

Client and server must use a known named pipe:

True

28
New cards
<p>Order of named-pipe operations</p>

Order of named-pipe operations

Create the name string, mkfifo, chmod, open

29
New cards

execvp creates a new process mirroring the caller

False (it replaces the current process image)

30
New cards

What two sockets must agree on

Protocol/type, IP address, and port

31
New cards
<p>Correct client socket order:</p>

Correct client socket order:

socket, connect, read/write, close

32
New cards

API not used in client code:

bind, listen, or accept

33
New cards
<p>IPC mechanisms that work across a network</p>

IPC mechanisms that work across a network

Sockets

34
New cards
<p>Item not related to sockets</p>

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.

35
New cards

Sockets cannot be used on the same machine

False

36
New cards
<p>Server-side order</p>

Server-side order

socket, bind, listen, accept, read/write

37
New cards

SOCK_STREAM

Reliable, connection-oriented byte stream (TCP)

38
New cards

Loopback IP address:

127.0.0.1

39
New cards

pthread_create start routine takes only one argument:

True (a single void *)

40
New cards

A pthread_start command is needed to start the thread

False

41
New cards

A process has one thread by default:

True

42
New cards

Building requires pthread.h and -pthread on the g++ line:

True

43
New cards

Segment not shared between threads:

Stack

44
New cards

Threads help because they can run longer than the process's allotted time

False

45
New cards
<p>Critical code section</p>

Critical code section

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

46
New cards
<p>Lock/unlock device: </p>

Lock/unlock device:

Mutex

47
New cards
<p>Call that waits for a thread to finish</p>

Call that waits for a thread to finish

pthread_join

48
New cards

Is cout thread safe:

False

49
New cards

Linux is:

Preemptive and time-shared

50
New cards

PaaS means Programming as a Service:

False