Final practice exam Flashcards

1
Q

What does the comma operator do?

A
  • sequences two expressions
  • value is the result of the righthand expression
  • treated as a single expression by the compiler
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are enumerated types?

A

-syntax: enum tag { values } vars ;
-each ‘value’ is an identifier - use them in expressions
-internally, represented as integers
- by default, first ‘value’ represented as 0
- subsequent ‘values’ have previous - entry’s representation + 1
- can override: name = integer
- sequence defines an ordering relationship between the ‘values’

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

What are qualifiers?

A
  • optimization hints to the compiler
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the forms of qualifiers?

A

register: keep this variable in a register if possible
volatile: variable’s contents may change between compiled statements
restrict: guarantee that *ptr is the only reference to something in this scope

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

What is the syntax for a macro with a parameter?

A

define name(params) value

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

What is a macro with a parameter?

A

each occurrence of a formal parameter in value is replaced by its actual parameter during macro expansion

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

What are the special uses of parameters

A

param: replaced by a string literal containing the actual parameter

##: creates a symbol during expansion

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

what is #error text?

A

generates a compilation error whose message includes text

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

What is #pragma text?

A
  • invokes a compiler-specific action
  • syntax and meaning of text are implementation-dependent
  • inherently non-portable!
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are some optimization tools?

A
  • profilers (e.g., gprof): analyze program behavior, determine number of calls to each function and total time spent in each function
  • code coverage (e.g., gcov): determine whether or not all code in a program can be reached
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is none as inefficient code?

A
  • excess code inside loop bodies (“loop invariants”)
  • unnecessary computation
  • common subexpressions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the big O notation for the search of unordered list?

A

O(n)

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

What is the big O notation for the search of a ordered list?

A

O(n/2)

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

What is the big O notation for a binary search tree?

A

O(logn)

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

What is the big O notation for a hash table?

A

O(1)

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

What is inefficient memory accessing?

A

primarily on large data sets in memory

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

What are things that affect performance?

A
  • efficiency of code produced by the compiler
  • efficiency of algorithms
  • redundant/unnecessary/useless code
  • data layout and access
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How to measure of some aspect of program behavior

A
  • CPU time used, “user” time, i/o operations, etc.
  • what matters depends on your point of view
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are the attributes in protection?

A
  • things in the file system have these
  • ownership (UID, GID)
  • permission bits (read, write, execute)
  • interpretation of permissions for files vs. directories
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is ownership in protection?

A
  • user id (UID), group id (GID)
  • each process has both IDs
  • OS uses these IDs to determine access rights
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How does altering ownership and accessing right in protection work?

A
  • “set” bits (set uid, set gid, sticky bit)
  • allow users to run programs with different UIDs/GIDs
  • ID variations:
    -real UID/GID: who is actually running the program
    -effective UID/GID: determine access rights to files (etc.)
    -saved UID/GID: “backup” of real UID/GID
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is protection?

A
  • OS as a collection of objects
  • characteristics of objects
  • Principle of Least Privilege
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What are the concepts of security?

A
  • threats, attacks, intruders
  • goals: confidentiality, integrity, availability
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is philosophy in security?

A

concept that protection is neccessary

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

What is policy in security?

A

A set of rules (who can use what)

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

What is mechanism in security?

A

How policy is enforced.

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

What are naive flaws?

A

Buffer overflow

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

What are examples of program flaws that are major sources of errors?

A

Apple SSL coding flaw
auth_overflow3 attack example
Morris Worm (1988)
other variations (trojan horses, time bombs, trapdoors)

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

What are pipes?

A

Connection between two file descriptors.

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

What does this do and mean? int pipe(int fd[2])

A

allocates two file descriptors.
data written into fd[1] can be read from fd[0]

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

How can file descriptors be moved to other file descriptor numbers?

A

Typically stdin and stdout.
int dup( fd );
int dup2( oldfd, newfd );

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

What are the concepts of OS: Scheduling?

A
  • goal: ensure that CPU time is used productively
  • scheduling: determining the order of execution of processes
  • dispatching: actually giving the CPU to a process
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What is the process behavior of OS: Scheduling?

A
  • process state transitions
  • bursts - cpu vs. i/o
  • typical distribution of burst length
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What are the process queues of scheduling?

A

OS uses queues to keep track of all processes
- ready queue: all processes which are able to execute
- device queues: processes which are blocked waiting for i/o
- sleep queue: processes which are blocked waiting for time to pass
etc.

34
Q

What does a context switch in scheduling do?

A
  • save CPU contents (process context) for currently-executing process
  • select a new “current” process
  • restore context for the “current” process
35
Q

What are the categories of schedulers?

A

Non-preemptive, voluntary yield, preemptive

36
Q

What do non-preemptive schedulers do?

A
  • behavior: never take the CPU away from a process
  • examples: FIFO, Shortest Job First
  • “run to completion” - once dispatched, job goes until it finishes
  • acceptable for batch processing, not really usable for interactive computing
37
Q

What do voluntary yield schedulers do?

A
  • behavior: no preemption
  • processes can “give up” the CPU to allow others to run
38
Q

What do preemptive schedulers do?

A
  • behavior: can “preempt” a process and give CPU to another process
  • examples: Round Robin, Multilevel Queue, Multilevel Feedback Queue
  • each process executes for a short time, then is preempted
  • over time, all processes get to execute and make progress
39
Q

What is quantum in scheduling?

A
  • a.k.a. “time slice”
  • length of time a process is allowed to execute before being preempted
  • critical to preemptive scheduling
40
Q

What are variations in scheduling?

A

Priorities and quantum length

41
Q

What are the priorities in variations?

A
  • indicate relative “importance” of processes
  • origin: internal (calculated by OS), external (requested by user)
  • duration: static (assigned when process arrives), dynamic (can change during process lifetime)
42
Q

What is quantum length in scheduling?

A
  • determined by OS/scheduler
  • can be identical for all processes, or different based on process type
  • duration: static (assigned when process arrives), dynamic (can change during process lifetime)
43
Q

What are the concepts in processes?

A
  • states
    new, ready, running, blocked, terminated, zombie, etc.
  • attributes (owner, PID, GID, etc.)
  • management by the OS
  • address spaces
44
Q

What are address spaces in processes?

A

They are virtual and physical spaces.
Parts of process address space.
- text,data,bss,heap,stack

45
Q

How to create a process?

A

pid_t fork( void ); system call
returns -1 on error
on success, now have two instances of the process
return value in child (new process): 0
return value in parent (original process): PID of the child
child inherits open i/o connections from parent
allows intermixing of i/o from both processes
can get unexpected results (e.g., stdio buffering example)

46
Q

How do you terminate a process?

A

terminating process produces an exit status
status must be collected by the parent
pid_t wait( int *status );
pid_t waitpid( pid_t pid, int *status, int options);
if parent doesn’t collect the status
terminated process becomes a zombie
stays in the system, occupying a process table slot
if parent has already exited, child is “re-parented” to the init process (typ., PID 1)
need for _exit() syscall (vs. exit())

47
Q

How do you execute other programs using processes?

A
  • exec family of system calls
  • replace the memory image of the process with a different program
  • many variants - most common two:
  • int execv( const char *path, char * const argv[] );
  • int execvp( const char *name, char * const argv[] );
48
Q

What is a thread?

A

A lightweight process. Provides the ability to perform concurrent operations within a single process context.

49
Q

What are the concepts of threads?

A
  • Threads execute inside a process context
  • all thread share code, global data areas, system resources (e.g., open files)
  • each thread has its own stack, CPU context (register contents), may have private data areas
50
Q

What are the potential issues of threads?

A
  • shared global data may lead to race conditions
  • result can be inaccurate/incomplete computation
  • concept: thread-safe code
51
Q

What are POSIX threads?

A
  • standardized thread model, usable on many (most?) systems
  • each thread identified by a pthread_t (thread ID)
52
Q

What does it mean when a thread is joinable?

A

-At termination, they stay in system until joined by another thread
- Threads can be detached aka non-joinable.

53
Q

What does it mean if a threads are in a cancellability state?

A

cancellation === termination
by default: enabled-thread can be cancelled by another thread
detached threads cant be cancelled

54
Q

What are the POSIX thread functions?

A

int pthread_create( pthread_t *id, const pthread_attr_t *attributes,
void (start_routine)(void *), void *arg );
void pthread_exit( void *retval );
int pthread_join( pthread_t id, void **retval );
int pthread_detach( pthread_t id );
int pthread_cancel( pthread_t id );

55
Q

What are the primary problems between threads?

A
  • critical resource: shared resource (e.g., variable)
  • critical section (C.S.): section of code using a critical resource
  • don’t want two or more threads in C.S. on same resource at the same time
  • interleaved execution can result in incorrect update/use of the shared resource
  • example: shared account balance, debit and credit threads
  • want operations on shared resources to be atomic (indivisible)
  • need a “locking” mechanism
56
Q

What are mutexes?

A
  • “locking” mechanism
  • provide mutual exclusion (mutex)
57
Q

What is the usage of mutexes?

A
  • thread attempts to lock the mutex before entering C.S. (entry guard)
  • after obtaining lock, thread executes C.S.
  • upon leaving C.S., thread unlocks the mutex (exit guard)
58
Q

What happens if two or more threads attempt to lock mutex simultaneously?

A
  • one thread “gets” the lock, the others are suspended
  • “winning” thread enters its C.S.
  • when this thread leaves its C.S., it unlocks the mutex
  • one of the suspended threads is awakened, the mutex is re-locked, and the awakened thread now enters its C.S.
59
Q

What are the mutex functions?

A
  • int pthread_mutex_init( pthread_mutex_t *mutex,
    const pthread_mutexattr_t *attributes );
  • int pthread_mutex_lock( pthread_mutex_t *mutex );
  • int pthread_mutex_unlock( pthread_mutex_t *mutex );
60
Q

Static global variables are stored in the _____ memory segment

A

DATA

61
Q

Static local variables are stored in _____ memory segment.

A

DATA

62
Q

Stack frames are stored in the _______ memory segment.

A

STACK

63
Q

Dynamic memory uses the ______ memory segment. If the code loses the _______ that holds its heap address, then there will be a memory leak.

A

HEAP, POINTER

64
Q

Memory allocated by calloc is stored in the _____ memory segment.

A

HEAP

65
Q

The instructions of the compiled code are stored in the _____ memory segment.

A

TEXT

66
Q

The C language is said to pass arrays by _______ because you can change the array’s contents, but it is really pass by _____.

A

REFERENCE, VALUE

67
Q

________ is used to increase efficiency while doing IO operations by reducing the number of read and write operations.

A

BUFFERING

68
Q

A _____ region is a section of code that multiple threads should not access at the same time.

A

CRITICAL

69
Q

A ______ is used to stop multiple threads from accessing the same section of code at the same time

A

MUTEX

70
Q

What do you write to use a particular C standard to control compilation?

A

-std

71
Q

What do you write to turn on all optional warnings?

A

-Wall

72
Q

What do you write to compile or assemble source files, but not link?

A

-c

73
Q

What do you write to place linking output in a specifically-names executable file?

A

-o

74
Q

What do you write to compile with additional information for debugging?

A

-ggdb

75
Q

What does “The language C provides no support for the data type “string” “ mean?

A

String in C is represented as an array of characters with a terminating NULL character ‘\0’

76
Q

What are the following steps of the program translation?

A

Preprocessing, Compilation, Assembling, Linking, Loading

77
Q

In which step does lexical and syntax analysis occur?

A

Compilation

78
Q

(T or F) The preprocessor checks the syntax of the C source code.

A

FALSE, Compiler

79
Q

Write a preprocessor macro to determine if a signed integer is negative.

A

define NEGATIVE (x) if(x<0)

80
Q

What is a fork?

A

Is a system call that is used for process creation. When a program calls fork(), the operating system creates a new process that is a copy of the calling (parent) process. The newly created process is referred to as the child process, and the original process is referred to as the parent process.

81
Q

How many processes does the following code create?
for(int i = 0; i < 5; i++){
fork();
}

A
  1. Because a fork creates copies. So think 2^n.
82
Q

Given the following struct (assume struct prof has already been defined):

Struct course{
int num_students;
char * name;
short building_num;

struct prof * professor;
short room_num;
}
a. What is the result of sizeof(struct course)?
b. Rewrite struct course to minimize the space it requires. What is its new size?

A

a) 40.
b) Struct
Char *
Int
Short
Short
24

83
Q
A