Test 3 Flashcards

Chapter 4 and 5

1
Q

What is a Preprocessing Directive

A
Any code that begins with #
#include
#define
#ifdef - if defined
#ifndef - if not defined
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is in a Header File

A
  • constant definitions
  • data type definitions
  • function prototypes (but not function implementations)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are 4 Steps of the Compilation Process

A
  1. Preprocessing
  2. Assembly Code Creation
  3. Machine Code Creation
  4. Linking
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are 2 Types of Linking

A

Static Linking: library code copied into executable
PROS: faster execution time
CONS: larger executable size
Dynamic Linking: library code is loaded at runtime
PROS: smaller executable size
CONS: slower execution time

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

What is a Makefile

A

a text file that is used by the make command to automatically build executable programs and libraries from source code

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

Makefiles: how do you declare a variable

A
  • declare at the top of the file
  • e.g. OBJ = linkExample1.o linkExample2.o
  • use variable with $(OBJ)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Makefiles: how do you clean?

A

clean:

rm -f *.o *~

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

What is concurrent computing

A

a form of computing where several computations are executed at the same time

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

What are the 3 main types of concurrent computing?

A

Multithreaded, multiple processors, and distributed systems

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

What is a distributed system?

A

a large program that is executed over multiple physical host machines that communicate via internet or intranet

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

What is a multi-process system?

A

a system running multiple processes/executables at the same time and they communicate with each other to accomplish a task

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

What is a multi-threaded system?

A

a single process with multiple control flows where multiple tasks are performed by the same CPU but they take turn sharing the CPUs resources

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

Name 3 common issues with concurrent computing

A
  1. Shared Resources
  2. Deadlocks
  3. Race conditions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In concurrent computing, what is the issue with shared resources? What are 2 methods for accessing shared variables?

A

Multiple threads or processes will likely need the same resources.

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

What is a Mutex?

A

MUTual EXclusion object
a program object created so multiple threads can take turns using it. only the thread that locked or acquired it can unlock it

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

What is a Semaphore?

A

A variable used to control access to a common resource
It is a generalization of a Mutex
A thread waiting on a semaphore can be signalled by a different thread so that it can have access

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

In concurrent computing, what are deadlocks?

A

a condition where multiple threads/processes are blocked and all waiting for a condition that will never occur
ALWAYS DUE TO IMPROPER MUTEX/SEMAPHORE HANDLING

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

In concurrent computing, what are race conditions?

A

a timing problem in which the correctness of a program depends on one thread reaching a point in control flow before another thread ( the order things get processed is never guaranteed)

19
Q

What is process management?

A

allocating resources to processes, enabling processes to share and exchange info, protecting resources of each process from each other, and enabling syncing of processes

20
Q

What are two ways that process management can occur?

A
Shell commands (in the command line)
System calls (in a program)
21
Q

Name the 4 main system calls

A

FORK
EXEC
WAIT
SYSTEM

22
Q

How does FORK work?

A

It creates a new process with the current process as the parent of the new process

When using the fork() function as an R-Value, (int i = fork()) the it returns different values in the parent and child processes

In the parent process, Fork returns the PID of the child
In the child process, Fork returns 0

23
Q

How does EXEC work?

A

Allows the code to go off and run another program instead of this continuing with this one (and it uses the same process ID)

int execv(const char *path, char *const argv[]);
int execvp(const char *file, char *const argv[]);
int execl(const char *path, const char *arg, ....more args);
int execlp(const char *file, const char *arg, ... more args);
path = full path to the file
file = "./fileName"
v = arguments as an array
l = arguments as a list
24
Q

How does WAIT work?

A

wait(): allows us to put a delay in a parent program until ONE of it’s children returns
waitpid(childPID, &status, 0): allows parent to wait until a specific child is returned

25
Q

How does SYSTEM work?

A

allows us to run specified commands (or programs) as a shell command
when called, the process blocks until the system call is done and then control returns to the program

26
Q

What is a signal?

A

An integer sent from one process to another

27
Q

What are the two user defined signals?

A

10: SIGUSR1
12: SIGUSR2

28
Q

How do you install a signal handler?

A

signal (SIGUSR1/SIGUSR2,signalHandlerFunction);

where signalHandlerFunction must take a single int parameter and return void
-can use SIG_IGN (ignore signal), or SIG_DFL (use default handler)

29
Q

How do you send signals to other processes

A

kill(pid,SIGNALTOSEND);
SIGNALTOSEND can be an integer or SIGUSR1, SIGUSR2, etc.

Some examples of signals are:
SIGINT-> signal interrupt (what happens when you press ctrl+C in terminal

30
Q

What is a socket?

A

An endpoint for sending or receiving data b/w processes

31
Q

How do two hosts communicate to each other through ports and IP addresses

A

Host 1 App unique port #transport LayerNetwork Layer -> IP Adress
\/
NETWORK
/\
IP Adress Network Layer Transport Layer unique port # App Host 2

32
Q

What is the transport layer?

A

A conceptual layer that indicates how indicates how exactly the data is transferred from source to destination (either TCP or UDP)

33
Q

What is the network layer?

A

provides the means of sending packets from a source host to a destination host

34
Q

What are the two main strategies for transfer layer

A

TCP: transmission control protocol
UDP: User Datagram protocol

35
Q

What are the 3 types of sockets

A

Stream Sockets: (used for TCP) (think like a telephone call)
- connection based, must have connection between sender and receiver before info is sent
- must close connection when finished
- used for reliable packet delivery
Datagram Sockets: (used for UDP) (think like a text message)
- data sent when ready
- fastest packet delivery, but they can be corrupted
Raw Sockets:
-bypasses the transport layer completely

36
Q

What is the client server model

A

a commonly used architecture where one process acts as a server that received requests and clients and then performs the tasks accordingly

37
Q

What are the steps for setting up a client-server model with TCP protocol

A

include

int sockID = socket( (AF_INET/AR_LOCAL) ,SOCK_STREAM,IPPROTO_TCP)

bind(sockID, <address>,);
address is of type struct sockaddr
we typecast to sockaddr from sockaddr_in
(struct sockadd*) addr (# of pending req’s that can be queued));

clientSock = accept(sockID, ,);

int numBytesRecd = recv(clientSock, (space in memory), , 0);

send (clientSock, buffer, bufferLength, 0 ); </address>

38
Q

What is the makefile structure

A

all: target1 target2
__TAB__| gcc -o programName target1.o target2.o
target1: target1.c target1.h extraStuff.h
__TAB__| gcc -c target1.c
target2: target2.c target2.h extraStuff2.h
__TAB__| gcc -c target2.c

39
Q

What are the steps for setting up a client server model with UDP protocol

A

serverSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_UDP);

select(,,, , )
numDescriptors = # of file descriptors/potential clients to accept
readFDS/writeFDS = sets of file descriptors ready for reading and writing
exceptFDS -> set to NULL
timeout -> set to NULL for waiting indefinitely, {0,0} to not wait

recvform(serverSocket, buffer, bufLen, 0, clientAddr*, clientAddrLength)

sendTo(serverSocket, buffer, bufLen, 0, clientAddr*, clientAddrLength);

40
Q

What is a file descriptor?

What is the file descriptor set struct?

A

an integer ID (handle) used to access a file or other input/output resources (e.g. pipe or socket)

struct fd_set can be used as follows:

int socket
fd_set readfds

FD_ZERO(&readfds)
FD_SET(socket,&readfds)

41
Q

What is a thread

A

a sequence of programmed instructions that can be managed independently by the OS

it is faster to switch threads than to switch processes

42
Q

What are some unique properties of each thread?

What are some shared properties of threads from the same process?

A

UNIQUE:

  • thread ID
  • function call stack
  • program counter

SHARED:

  • address space
  • data segment
  • code segment
43
Q

What are the thread functions and how do you use them?

A

pthread_create(pthread_t addr, NULL, functionPointer, functionParameter)

pthread_exit(void *status)
status variable allows the thread to return something

pthread_join(pthread_t thread, void *status)
waits until the specified thread ends

44
Q

How do you use semaphores?

A

include

sem_t semEx;
sem_init(&semEx,0,1);
volatile int count = 0;

sem_wait(&semEx); //returns 0 if all goes well
count++;
sem_post(&semEx);//return 0 if good, increments the semaphore value