Ch5: Concurrent Computing Flashcards

(28 cards)

1
Q

Differences between process and thread

A
  • Process is independent executable with independent virtual memory and control flow
  • Threads are part of processes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does a mutex do

A
  • control access to shared resource
  • only thread that obtains mutex can access shared resource
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does a semaphore do

A
  • variable, generalization of mutex
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are 4 things every process have

A
  • PID (process ID)
  • PPID (parent process ID)
  • independent address space and virtual memory
  • control flow
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does fork() do and return

A
  • creates new process running two copies of the remaining code along with parent process
  • child process returns 0
  • parent process returns child PID
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What do exec() family functions do

A
  • runs another program with same PID
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does wait() do

A
  • puts delay in parent process until a child process returns
  • returns PID of child process that ended
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does system() do

A
  • run specified command or program as shell command
  • when called, process blocked until command is finished, then control is returned to process
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the two main approaches to IPC?

A
  • signals: int value sent from one process to another, can only be used on same host
  • sockets: endpoints for sending or receiving data between processes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does signal(SIGUSR1, sigHandler) do

A
  • first parameter takes signal code
  • second parameter is signal-handling function name
  • signal handler functions are void with single int parameter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does kill() function do

A
  • first parameter is PID of target process
  • second parameter is signal code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to identify a process when using sockets

A
  • IP address: unique to each host (computer) on the same network
  • port number: unique identifier of processes on the host
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the two main transport layers

A
  • TCP (transport control protocol)
  • UDP (user datagram protocol)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the 3 types of sockets and what transport layer do they work with

A

Stream socket: connection must be established then closed, best for reliable in-order delivery, TCP
Datagram socket: connectionless, data sent when ready, faster sending but no reliable order, UDP
Raw socket: bypass transport layer

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

What does the kernel do

A
  • Intermediary between hardware and user programs
  • Manages memory, execution of programs, communication w/ devices
  • builds process table to keep track of processes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are possible values for the second parameter of signal()

A
  • SIG_IGN: ignore
  • SIG_DFL: default handling
  • Signal handler function: call this function
17
Q

What is an orphan process

A
  • a process where parent process terminated without terminating child
18
Q

What is a zombie process

A
  • a child process that has exited but is still in process table
  • waiting for parent to look at its return value
19
Q

What are the connection steps for a TCP server

A
  • create stream socket
  • bind socket to server’s IP address and port #
  • listen on socket for incoming client connection requests
  • accept client connection
  • receive/send data
  • close socket
20
Q

What are the connection steps for a TCP client

A
  • create stream socket
  • connect to server at its IP address and port #
  • send/receive data
  • close socket
21
Q

What’s the process for a UDP server

A
  • create datagram socket where messages are received
  • bind socket to server’s IP address and port #
  • select incoming message from client
  • receive/send data
  • close socket
22
Q

What’s the process for a TCP server

A
  • create datagram socket to connect to server
  • connect to server at its IP address and port #
  • send/receive data
  • close socket
23
Q

What are thread contexts

A
  • unique resources to each thread
    includes:
  • unique thread ID
  • unique function call stack
  • program counter (keep track of current executing instruction)
24
Q

What do threads share

A
  • address space
  • data segment
  • code segment
25
What are the 4 parameters of pthread_create()
- pointer to pthread_t variable (stores int id - attributes used by thread (often NULL) - pointer to start function called to start thread - single parameter that can be passed to start function
26
How to terminate a thread
- to stop: pthread_exit(void *status) - status is return value of thread - to wait for another thread to terminate: pthread_join(pthread_t thread, void **status)
27
How to initiate a semphore
sem_t semaphore; sem_init(&semaphore, 0, 1); address of sem_t object, 0 to indicate it's shared between threads, 1 as initial value (available)
28
Semaphore wrapper functions
sem_wait(&semaphore) sem_post(&semaphore)