Final practice exam Flashcards

(84 cards)

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
What is policy in security?
A set of rules (who can use what)
25
What is mechanism in security?
How policy is enforced.
26
What are naive flaws?
Buffer overflow
27
What are examples of program flaws that are major sources of errors?
Apple SSL coding flaw auth_overflow3 attack example Morris Worm (1988) other variations (trojan horses, time bombs, trapdoors)
28
What are pipes?
Connection between two file descriptors.
29
What does this do and mean? int pipe(int fd[2])
allocates two file descriptors. data written into fd[1] can be read from fd[0]
30
How can file descriptors be moved to other file descriptor numbers?
Typically stdin and stdout. int dup( fd ); int dup2( oldfd, newfd );
31
What are the concepts of OS: Scheduling?
- goal: ensure that CPU time is used productively - scheduling: determining the order of execution of processes - dispatching: actually giving the CPU to a process
32
What is the process behavior of OS: Scheduling?
- process state transitions - bursts - cpu vs. i/o - typical distribution of burst length
33
What are the process queues of scheduling?
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
What does a context switch in scheduling do?
- save CPU contents (process context) for currently-executing process - select a new "current" process - restore context for the "current" process
35
What are the categories of schedulers?
Non-preemptive, voluntary yield, preemptive
36
What do non-preemptive schedulers do?
- 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
What do voluntary yield schedulers do?
- behavior: no preemption - processes can "give up" the CPU to allow others to run
38
What do preemptive schedulers do?
- 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
What is quantum in scheduling?
- a.k.a. "time slice" - length of time a process is allowed to execute before being preempted - critical to preemptive scheduling
40
What are variations in scheduling?
Priorities and quantum length
41
What are the priorities in variations?
- 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
What is quantum length in scheduling?
- 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
What are the concepts in processes?
- states new, ready, running, blocked, terminated, zombie, etc. - attributes (owner, PID, GID, etc.) - management by the OS - address spaces
44
What are address spaces in processes?
They are virtual and physical spaces. Parts of process address space. - text,data,bss,heap,stack
45
How to create a process?
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
How do you terminate a process?
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
How do you execute other programs using processes?
- 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
What is a thread?
A lightweight process. Provides the ability to perform concurrent operations within a single process context.
49
What are the concepts of threads?
- 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
What are the potential issues of threads?
- shared global data may lead to race conditions - result can be inaccurate/incomplete computation - concept: thread-safe code
51
What are POSIX threads?
- standardized thread model, usable on many (most?) systems - each thread identified by a pthread_t (thread ID)
52
What does it mean when a thread is joinable?
-At termination, they stay in system until joined by another thread - Threads can be detached aka non-joinable.
53
What does it mean if a threads are in a cancellability state?
cancellation === termination by default: enabled-thread can be cancelled by another thread detached threads cant be cancelled
54
What are the POSIX thread functions?
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
What are the primary problems between threads?
- 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
What are mutexes?
- "locking" mechanism - provide mutual exclusion (mutex)
57
What is the usage of mutexes?
- 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
What happens if two or more threads attempt to lock mutex simultaneously?
- 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
What are the mutex functions?
- 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
Static global variables are stored in the _____ memory segment
DATA
61
Static local variables are stored in _____ memory segment.
DATA
62
Stack frames are stored in the _______ memory segment.
STACK
63
Dynamic memory uses the ______ memory segment. If the code loses the _______ that holds its heap address, then there will be a memory leak.
HEAP, POINTER
64
Memory allocated by calloc is stored in the _____ memory segment.
HEAP
65
The instructions of the compiled code are stored in the _____ memory segment.
TEXT
66
The C language is said to pass arrays by _______ because you can change the array's contents, but it is really pass by _____.
REFERENCE, VALUE
67
________ is used to increase efficiency while doing IO operations by reducing the number of read and write operations.
BUFFERING
68
A _____ region is a section of code that multiple threads should not access at the same time.
CRITICAL
69
A ______ is used to stop multiple threads from accessing the same section of code at the same time
MUTEX
70
What do you write to use a particular C standard to control compilation?
-std
71
What do you write to turn on all optional warnings?
-Wall
72
What do you write to compile or assemble source files, but not link?
-c
73
What do you write to place linking output in a specifically-names executable file?
-o
74
What do you write to compile with additional information for debugging?
-ggdb
75
What does "The language C provides no support for the data type "string" " mean?
String in C is represented as an array of characters with a terminating NULL character '\0'
76
What are the following steps of the program translation?
Preprocessing, Compilation, Assembling, Linking, Loading
77
In which step does lexical and syntax analysis occur?
Compilation
78
(T or F) The preprocessor checks the syntax of the C source code.
FALSE, Compiler
79
Write a preprocessor macro to determine if a signed integer is negative.
#define NEGATIVE (x) if(x<0)
80
What is a fork?
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
How many processes does the following code create? for(int i = 0; i < 5; i++){ fork(); }
32. Because a fork creates copies. So think 2^n.
82
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) 40. b) Struct Char * Int Short Short 24
83