1/103
Flashcards for the lectures spanning lecture 11 and lecture 21
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What are pointers to functions often used to implement?
Polymorphism
What will the compiler mistake the pointer name for if it is not encapsulated in parentheses?
Function prototype
What is a struct?
A user defined data type that is used to group items of different types into a single type
What are the items inside a struct known as?
Members
How are values in structs stored in memory?
Stored contiguously in memory
We can directly access members of a structure using what operator?
The period
When accessing members of a structure using pointers, what operator must we use?
The arrow operator
Why is it more efficient to pass a pointer to a function vs the entire structure?
Only the memory address is passed, not a copy of the entire struct
Is explicit memory allocation faster than implicit memory allocation?
Yes, explicit memory allocation is faster
Do explicit memory allocations use more or less memory compared to implicit memory allocation?
Explicit memory allocation uses less memory
Enums are a special user defined data type that are used to represent what?
A group of global constants
Why might it be better to use an Enum instead of using #define?
Enum allows us to group related values together which follow bounds checking and scope rules. #define does not group values together, it just creates a macro for a global static variable
What issues may arise from #define?
What is the default value assigned to each member of the enum?
The default value will start at 0
Following the default value, what value is assigned to each subsequent enum value?
Each subsequent value will be assigned a value 1 greater than the last
If there is an enum with the first value set to 20, what is the subsequent value?
21
What is a union?
A user defined data type consisting of a sequence of members whose storage overlaps
When we define a union we can store a variety of data types, but where/how is everything stored in memory?
All members share the same memory space
Based on memory spacing of unions, how many members can hold a value at one time?
The value of at most one member at a time can be stored in a union
How do you determine the size of the union?
The size of the union is based on the size of its largest member
Why are unions useful (benefits of a union)?
Unions can save space by sharing memory for different types of data
What operator do we use to access members of a union?
The period ( . ) operator
What is BASH?
The Bourne Again Shell (bash) is a command interpreter and a high-level programming language
When using the shell as a programming language, it processes commands where?
Commands stored in files called shell scripts
What is the special sequence of characters needed on the first line when scripting?
Why is shebang needed?
It helps tell the operating system which shell should execute the file
Ways you can cause the shell to alter where standard input of a command comes from and where standard output goes to is known as what?
Redirection
What symbol represents standard output redirection?
or 1>
What symbol represents standard input redirection?
< or 0<
What symbol represents standard error redirection?
2>
What symbol represents append output redirection?
>
What does redirecting with a > do?
Instructs the shell to redirect the output of a command to the specified file instead of to the screen
What does redirecting with a < do?
Instructs the shell to redirect input of a command from a file
What does redirecting with a >> do?
Causes the shell to add new information to the end of a file, leaving existing information intact
What does redirecting with a 2> do?
Redirects output to standard error
What is a file descriptor?
Is the place a program sends its output to and gets its input from
What is /etc/passwd?
Is a list of users recognized by the system
What is /etc/shadow used for?
Where actual passwords are stored
What are the first four fields of a /etc/passwd entry represent?
Login name, Placeholder for the password, User ID, Group ID
List the first step in adding a node to the front of a doubly linked list
Create a new node using malloc
List the first step in adding a node to the tail of a doubly linked list
We create a new node using malloc
What do header files include?
Includes C declarations and macro definitions to be shared across multiple files
The C preprocessing directive #include is a request to the compiler to do what?
To load the contents of a specific header file, so that they can be used in the program
What is double inclusion?
Including the same header file twice across multiple files
What is the solution for double inclusion?
Header guards
When using header guards the preprocess will check what?
Whether the header guards unique name has been previously defined in the translation unit
What is linking?
Is the process of collecting and combining various pieces of code and data into a single file that can be copied into memory and executed
What are the three benefits of linking multiple files together versus creating one large source file?
Modularity, easier to maintain smaller more manageable modules than one big one, code can be reused
What is symbol resolution?
Is to associate each symbol reference with exactly one symbol definition
What is a symbol?
Global variables and functions
What is the symbol table?
Is an array of structs
What does each symbol entry include?
Includes name, size, and location of the symbol
What is relocation?
Compilers and assemblers generate code and data sections that start at address 0, The linker relocates these sections by associating a memory location with each symbol definition, Then modifying all of the references to those symbols so that they point to this memory location
What are the three different types of object files?
Relocatable object file (.o), Executable object file (a.out), Shared object file (.so)
What are global, external, and local symbols?
Global, symbols defined by module m that can be referenced by other modules, External, global symbols that are referenced by module m but defined by some other module, Local, symbols that are defined and referenced exclusively by module m
What are the three rules when dealing with duplicate symbols?
Rule 1: Multiple strong symbols are not allowed, Rule 2: Given a strong symbol and multiple weak symbols, choose the strong symbol, Rule 3: If there are multiple weak symbols, pick an arbitrary one
Why is it bad to put all standard C functions into a single relocatable object module?
It is a huge waste of space as every executable file in the system would have a copy of these functions even if they are not using them, Changing any of the functions would require recompilation of the entire source code
Static libraries are stored on disk in a format known as what?
Archive (.a)
What are the disadvantages of static libraries?
Duplication in the stored executables (every function needs libc), Duplication in the running executables, Minor bug fixes of system libraries require each application to explicitly relink
What modern solution is available that is made of object files that contain code and data that are loaded and linked into an application dynamically, at either load-time or run-time?
Shared libraries (DLL’s) or Shared object (.so) files
What is dynamic linking?
An object module that, at either runtime or load time, can be loaded at an arbitrary memory address and linked with a program in memory
What is the simplest form of control flow?
Is a “smooth” sequence where instructions are adjacent in memory
Abrupt changes in control on the system are referred to as what?
Exceptional Control Flow (ECF)
The process of transferring control to the OS kernel in response to some events is called what?
Exception
What is a process?
Is an instance of a program in execution
What does preempted mean?
Temporarily suspended
A logical flow whose execution overlaps in time with another flow is called what?
A concurrent flow, the two flows are said to run concurrently
What is the first process in the system?
Init or systemd
What is the ID assigned assigned to every process by the kernel called?
Process ID
Which process states means the process is waiting for an event or resources?
Sleeping/Waiting
Which process state means the process is trying to exit?
Zombie
Which process state means the process is suspended (not allowed to execute)
Stopped
What is the process table?
The process table contains all information about each process
What is a process control block?
Each process table entry contains enough information to restart (put in running state) a process that is waiting or in a ready state
What is a context switch?
Control flow passes from one process to another
What is a thread?
Is a path of execution
What advantages are gained when using multithreading?
Fast thread creation, fast context switch, fast communication across threads
What are the advantages of multiprocessing?
Reduced execution time, parallel execution, process isolation
What does fork do?
Returns 0 to the child process, child’s PID to parent process
What is a race condition?
Threads can access shared data and try to change it at the same time
What is a mutex lock?
A mutex lock, otherwise known as mutual exclusion, is an operation used to prevent simultaneous possession of shared resources
What is the critical section?
Is a portion of code only one thread should execute at a time
What is a semaphore?
Is a global variable with a nonnegative integer value that can only be manipulated by two functions
What are the two functions used to lock and unlock a semaphore?
semwait() and semsignal()
What is the main objective of multiprogramming?
To have some process running at all times, maximizing CPU utilization
What is the responsibility of the CPU scheduler?
When the CPU becomes idle, the CPU scheduler selects a process from the processes in memory that are ready to execute and allocates the CPU to that process
What's a preemptive scheme?
The OS can interrupt a running process and switch to another process before the current one finishes
What is a signal?
Is a small message that notifies a process that an event of some type has occurred in the system
For what two reasons can a signal be sent?
The kernel detected a system event (like divide by zero), A process has invoked the kill function that requires the kernel to send a signal to the process
When a process receives a signal, what three actions can it take?
Ignore, Terminate, Catch
What is a pending signal?
A signal has been sent but not yet received
What are blocked signals?
A process can selectively block the receipt of certain signals, Blocked signals can be delivered but the pending signal will not be received until the process unblocks the signal
Each signal type has a predefined default action, what are the four actions?
The process terminates, The process terminates and dumps the core, The process stops (suspends) until restarted by a SIGCONT signal, The process ignores the signal
A transaction between a client and a server consists of four steps, what are they?
The client initiates a request to the server, The server receives the request, understands what it is asking for, then processes the request, The server then sends a response to the client, and waits for a new request, The client receives the response and processes it
A network is a hierarchical system organized by geographical proximity, what are the three proximities?
SAN (System area network), LAN (Local area network), WAN (Wide area network)
How are IP addresses stored in memory for a network?
IP addresses are stored in network byte order, Otherwise known as big-endian byte order
What is a socket?
An endpoint of a connection
What is a socket pair?
A socket address is (IP_Address:Port), Connection socket pair is (Client socket address, server socket address)
What is an ephemeral port?
Assigned automatically by client kernel when client makes a connection request
What is a well-known port?
Associated with some service provided by a server (e.g., port 80 is associated with Web servers)