Podcast
Questions and Answers
What is the primary purpose of function pointers in C?
What is the primary purpose of function pointers in C?
- To define new data types.
- To implement polymorphism. (correct)
- To manage memory allocation.
- To create dynamic arrays.
In C, if the pointer name isn't encapsulated in parentheses, the compiler will always understand it as intended.
In C, if the pointer name isn't encapsulated in parentheses, the compiler will always understand it as intended.
False (B)
What is a struct in C programming?
What is a struct in C programming?
A user defined data type that is used to group items of different types into a single type
When accessing members of a structure using pointers, you must use the ______ operator.
When accessing members of a structure using pointers, you must use the ______ operator.
Match the following memory allocation types with their characteristics:
Match the following memory allocation types with their characteristics:
What do enums primarily represent?
What do enums primarily represent?
Using an enum provides type checking and obeys scope rules, unlike #define
.
Using an enum provides type checking and obeys scope rules, unlike #define
.
What is the default value assigned to the first member of an enum if no explicit value is given?
What is the default value assigned to the first member of an enum if no explicit value is given?
The size of a union is determined by the size of its ______ member.
The size of a union is determined by the size of its ______ member.
Match the following concepts related to C unions:
Match the following concepts related to C unions:
What operator is used to access members of a union in C?
What operator is used to access members of a union in C?
BASH is exclusively a high-level programming language and not a command interpreter.
BASH is exclusively a high-level programming language and not a command interpreter.
What special sequence of characters is typically found on the first line of a BASH script, and what is it called?
What special sequence of characters is typically found on the first line of a BASH script, and what is it called?
In BASH, the permission combination 777
grants ______ , ______ , and ______ to the owner, group, and others.
In BASH, the permission combination 777
grants ______ , ______ , and ______ to the owner, group, and others.
Match the following BASH permission codes with their corresponding access rights:
Match the following BASH permission codes with their corresponding access rights:
In the context of BASH scripting, what does 'redirection' refer to?
In the context of BASH scripting, what does 'redirection' refer to?
A file descriptor is simply a name for a file.
A file descriptor is simply a name for a file.
What is the purpose of the /etc/passwd
file in Linux systems?
What is the purpose of the /etc/passwd
file in Linux systems?
Actual passwords are not stored directly in /etc/passwd
; instead, they are stored ______.
Actual passwords are not stored directly in /etc/passwd
; instead, they are stored ______.
Match the file descriptor with its corresponding description:
Match the file descriptor with its corresponding description:
Which of the following best describes 'polymorphism' as implemented using function pointers?
Which of the following best describes 'polymorphism' as implemented using function pointers?
Explicit memory allocation is always faster and more efficient than implicit memory allocation.
Explicit memory allocation is always faster and more efficient than implicit memory allocation.
What operator accesses members of a structure when using a pointer to that structure?
What operator accesses members of a structure when using a pointer to that structure?
Enums offer safety over #define
by providing ______ and obeying ______.
Enums offer safety over #define
by providing ______ and obeying ______.
Match each file permission number with its corresponding permission set (for a user, group, or others category):
Match each file permission number with its corresponding permission set (for a user, group, or others category):
Which data structure can be built using dynamic memory allocation?
Which data structure can be built using dynamic memory allocation?
Header files do not need to be included to utilize the functions within them.
Header files do not need to be included to utilize the functions within them.
What is the purpose of symbol resolution in the context of linking?
What is the purpose of symbol resolution in the context of linking?
The process of collecting and combining various pieces of code and data into a single file that can be copied into memory and executed is called ______.
The process of collecting and combining various pieces of code and data into a single file that can be copied into memory and executed is called ______.
Match the type of symbol with its scope:
Match the type of symbol with its scope:
What is the primary disadvantage of using static libraries?
What is the primary disadvantage of using static libraries?
Dynamic linking occurs only at compile time.
Dynamic linking occurs only at compile time.
What is a 'shebang' and why is it important in scripting?
What is a 'shebang' and why is it important in scripting?
The simplest form of control flow in a computer system is from ______ to ______.
The simplest form of control flow in a computer system is from ______ to ______.
Match each kind of exception with its basic description:
Match each kind of exception with its basic description:
What is the term for an instance of a program in execution?
What is the term for an instance of a program in execution?
In a multitasking system, processes always run to completion without interruption.
In a multitasking system, processes always run to completion without interruption.
What does it mean for a process to be 'preempted'?
What does it mean for a process to be 'preempted'?
The first process initiated in a Linux system is typically named ______.
The first process initiated in a Linux system is typically named ______.
Match the process state to its description:
Match the process state to its description:
What is stored in the process table?
What is stored in the process table?
The Process Identifier (PID) is assigned after the context switch takes place.
The Process Identifier (PID) is assigned after the context switch takes place.
What is the general goal of multiprogramming?
What is the general goal of multiprogramming?
A synchronization construct that allows one thread at a time to access a shared resource is known as a ______.
A synchronization construct that allows one thread at a time to access a shared resource is known as a ______.
Match each term related to process management with its correct description:
Match each term related to process management with its correct description:
Flashcards
What is Polymorphism?
What is Polymorphism?
Ability to change behavior at run-time.
What is a struct?
What is a struct?
A user-defined data type to group different types of items into a single type.
What are struct members?
What are struct members?
Items declared inside a struct.
How are struct values stored?
How are struct values stored?
Signup and view all the flashcards
What is dynamic memory allocation useful for?
What is dynamic memory allocation useful for?
Signup and view all the flashcards
How to access struct members with pointers?
How to access struct members with pointers?
Signup and view all the flashcards
Why pass a pointer to a function?
Why pass a pointer to a function?
Signup and view all the flashcards
Is explicit allocation faster than implicit?
Is explicit allocation faster than implicit?
Signup and view all the flashcards
Explicit allocation, regarding memory?
Explicit allocation, regarding memory?
Signup and view all the flashcards
What do enums represent?
What do enums represent?
Signup and view all the flashcards
Why might it be better to use an Enum?
Why might it be better to use an Enum?
Signup and view all the flashcards
What issues may arise from #define?
What issues may arise from #define?
Signup and view all the flashcards
Enum default value?
Enum default value?
Signup and view all the flashcards
What is a union?
What is a union?
Signup and view all the flashcards
How are union members stored?
How are union members stored?
Signup and view all the flashcards
How to determine the size of the union?
How to determine the size of the union?
Signup and view all the flashcards
Why are unions useful?
Why are unions useful?
Signup and view all the flashcards
What is BASH?
What is BASH?
Signup and view all the flashcards
Special sequence of characters to start scripting?
Special sequence of characters to start scripting?
Signup and view all the flashcards
What is shebang for?
What is shebang for?
Signup and view all the flashcards
What is redirection?
What is redirection?
Signup and view all the flashcards
What is a file descriptor?
What is a file descriptor?
Signup and view all the flashcards
What do header files include?
What do header files include?
Signup and view all the flashcards
What does #include do?
What does #include do?
Signup and view all the flashcards
What is double inclusion?
What is double inclusion?
Signup and view all the flashcards
What is the solution for double inclusion?
What is the solution for double inclusion?
Signup and view all the flashcards
How do header guards work?
How do header guards work?
Signup and view all the flashcards
What is linking?
What is linking?
Signup and view all the flashcards
When can linking happen?
When can linking happen?
Signup and view all the flashcards
Benefits of linking multiple files?
Benefits of linking multiple files?
Signup and view all the flashcards
What is symbol resolution?
What is symbol resolution?
Signup and view all the flashcards
What is the symbol table?
What is the symbol table?
Signup and view all the flashcards
Three types of object files?
Three types of object files?
Signup and view all the flashcards
Types of symbols?
Types of symbols?
Signup and view all the flashcards
Bad to put all C functions in one object?
Bad to put all C functions in one object?
Signup and view all the flashcards
How static libraries are stored on disk?
How static libraries are stored on disk?
Signup and view all the flashcards
Static libraries disadvantages?
Static libraries disadvantages?
Signup and view all the flashcards
Dynamic linking's timing?
Dynamic linking's timing?
Signup and view all the flashcards
Simplest form of control flow?
Simplest form of control flow?
Signup and view all the flashcards
Abrupt changes in system control?
Abrupt changes in system control?
Signup and view all the flashcards
Study Notes
- These notes cover topics from CSIT 231 Final Exam Study Guide
Lecture 11
- Pointers to functions often implement Polymorphism
- This changes behavior because it can change at run-time, which differs from static function calls
- Without parentheses around the pointer name in a function pointer, the compiler will make a mistake
- A struct is a user-defined data type used to group items of different types into a single type
- Items inside a struct are known as members
- Values in structs are stored contiguously in memory
- Members of a structure can be directly accessed using the "." operator
- Dynamic memory allocation is useful when the size or number of structures is unknown at compile time
- Dynamic memory allocation is useful for building data structures like linked lists, trees, and graphs
- When accessing members of a structure using pointers, the arrow operator (->) must be used
- Passing a pointer to a function is more efficient than passing the entire structure because only the memory address is passed, not a copy of the entire struct
- Explicit memory allocation is faster than implicit memory allocation
- Explicit memory allocation uses less memory but throws more errors
Lecture 12
- Enums are a user-defined data type to represent a group of global constants
- "The Days of the Week" is an example of an Enum
- Using an Enum instead of #define is better because it includes type checking and obeys scope rules
- #define can cause issues as it cannot group related variables
- The default value assigned to each member of the enum is 0
- Each value after the first increases by 1
- For the enum Weekdays { MONDAY = 20, TUESDAY = 30, WEDNESDAY = 40, THURSDAY = 50, FRIDAY = 60 };, Tuesday = 30, Thursday = 50
- A union is a user-defined data type consisting of a sequence of members whose storage overlaps
- When a union is defined, code can store a variety of data types, but since memory is all-shared memory space, only one member can hold a value at any given time
- Only one member can hold a value at a time
- The size of a union is based on the size of its largest member
- Unions are useful because they save space and memory and are useful for plugins and slicing network packets
- Members of a union are accessed using the "." operator
Lecture 13
- BASH, the Bourne Again Shell, is a command interpreter and a high-level programming language
- The special sequence of characters needed on the first line when scripting is the shebang (#!) / (#!/bin/bash)
- It tells the OS which shell should execute the file and follows the pathname
- When creating a script, permissions must be updated to read and execute the instructions
- Permission combinations:
- 777 → Reads, writes, and executes for the owner, group, and others
- 666 → Reads and writes for everyone
- 444 → Read-only for everyone
- Permissions can be adjusted using numbers to set specific permissions for each category: owner, group, others
- Redirection encompasses the ways to alter where the standard input of a command comes from and where the standard output goes
- < and > symbols are used to represent redirection
- A file descriptor is where a program sends its output and gets its input from
- There are three: Standard input, Standard output, standard error
- "/etc/passwd" is important for reading and identifying users
- The location where actual passwords are stored is important
- The first four fields of a /etc/passwd entry represent something important
Lecture 14
- The steps needed to add a node to the front of a list in a doubly-linked list are important
- The steps needed to add a node to the tail of a list in a doubly-linked list are important
- A doubly linked list is defined using a struct:
- struct Node { int data; struct Node* next; struct Node* prev; };
- struct Node* createNode (int data) { struct Node* newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = data; newNode->next = NULL; newNode->prev = NULL; return newNode; }
Lecture 14_3
- Header files include #include <header.h>
- The C preprocessing directive #include requests the compiler to load the contents of a specific header file so it can be used in the program
- Double inclusion is when the including header file is in multiple files
- To solve double inclusion, include the same header file twice or use a Header Guard
- Header guards check if a header has been defined before and prevents being defined more than once
- Linking is the process of collecting and combining various pieces of code and data into a single file to be copied into memory and executed
- Linking can be done at compile time, load time, and run time
- Linking multiple files together leads to better optimization compared to creating one large source file
Lecture 15
- Symbol resolution associates each symbol reference with exactly one symbol definition
- A symbol table is an array of structs
- Each entry contains the name, size, and location of the symbol
- There are three object files:
- Relocatable object (.o file)
- Executable object file (a.out file)
- Shared object file (.so file)
- There are global, external, and local symbols
- Rules for dealing with duplicate symbols:
- Multiple strong symbols are not allowed, and each item can be defined only once
- Using multiple strong symbols causes a Linker Error
- Given a strong symbol and multiple weak symbols, choose the strong symbol
- If there are multiple weak symbols, pick an arbitrary one
Lecture 16_2
- Putting all standard C functions into a single relocatable object module causes huge waste of space, and a change would require recompilation of the entire source code
- Static libraries are stored on disk in an archive file format
- Disadvantages of static libraries:
- Duplication in stored executable files
- Duplication in running executable files
- Minor bug fixes of system libraries require each application to explicitly relink
- Shared Libraries are a modern solution
Lecture 17
- Dynamic linking occurs during runtime or load time, when a library is loaded at an arbitrary memory address and linked with a program in memory
- Shared libraries are "shared" either through one .so file or a single copy of the text section of a shared library in memory
- The simplest form of control flow is startup to shutdown, where a CPU reads and executes a sequence of instructions one at a time which is CPU Control Flow
- Events causing abrupt changes in the system: Instruction divides by zero, data from disk or network adapter, control, and hardware timer goes off
- These abrupt changes are referred to as Exceptional Control Flow (ECF)
- Exceptional control flow can occur at the hardware, OS, and application level
- An exception is the transfer of control to the OS kernel in response to some event, like a change in the processor state
- Events are triggered by any significant change
Cont.
- Each type of event has a unique exception number k
- k = index into exception table, also known as an interrupt vector
- Handler k is called each time exception k occurs
- The four classes of exceptions:
- Interrupts
- Traps
- Faults
- Aborts
- A process is an instance of a program executing
- While processes are running, using a logical control flow, they take turns using the processor
- While processes take turns, they are preempted, meaning they are temporarily suspended
- A logical flow whose execution overlaps in time with another flow is called a concurrent flow
Lecture 18
- Init. is the first process in the system
- The kernel assigns a unique ID number to every process
- The unique ID is called the PID (Process ID)
- Relationships between processes are named Parent-child
- The states a process may be in:
- Ready/Runnable
- Running
- Zombie
- Stopped
- Terminated
- Sleeping
- The process table contains all the info for processes
- a process control block (PCB) stores process info
- A context switch forcefully takes resources or the CPU from a process
- A context switch happens approximately every 1/100sec
- A thread is a path execution
- Every thread has its own:
- Stack
- PC - Program Counter
- Set of registers
- State
- Multithreading Advantages:
- Fast creation, context switch, and communication across
- Multithreading Disadvantages:
- Less robust or more sync problems
- Multiprocessing Advantages:
- Reduced Execution Time, Parallel exec, Process Isolation
- Multiprocessing Disadvantages:
- Memory and CPU Overhead *higher usage
- Fork: A running child process that is called once but returns twice
Lecture 19
- Code will be provided to read, understand multithreading and multiprocessing codes, along with a process graph
- A race condition is when threads can access shared data and try to change it simultaneously
- A mutex lock, also known as a mutual exclusion, is an operation used to prevent simultaneous possession of the shared resources
- The critical section is the portion of the code only one thread should execute at a time
Cont.
- Semaphores coordinate access to resources
- The two types of semaphores are binary and counting
- The functions that lock/unlock a semaphore are Sem_post(), sem_wait()
Lecture 20
- A signal is a small message that notifies a process that an event of some type has occurred in the system
- A signal may be sent by sending or receiving
- When receiving a process, the process can do one of three things: Ignore, Catch, Terminate
- A pending signal has been sent but not yet received
- Blocked signals are signals a process can selectively block the receipt of certain signals
- There can be at most one pending signal of a particular type, the rest of the signals that may be of the same type are discarded
- Each signal type has a predefined default action. The four actions:
- The process terminates
- The Process terminates and dumps 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:
- The client initiates a request to the server
- The server verifies and approves the request
- The server then sends a response to the client and waits
- The client receives the response then processes it
- A network is a hierarchical system organized by geographical proximity
- The three proximities: SAN, LAN, WAN
- IP addresses are stored in memory for a network and are referred to as "Dotted Decinal notation"
- Usually IPs are presented to humans in a dotted decimal format, which is a conversion from its original hex form
- A socket is an endpoint of a connection
- A socket pair is (IP_adress:port)
- An Ephemeral port is assigned automatically by the client kernel when a client makes a connection request
- Well-known port is associated with some service provided by a server
- Byte order is converted between the network and the client
- AF_INET is used for the internet
Lecture 21
- The main objective of multiprogramming is to have some process always running, maximizing CPU utilization
- CPU sitting idle is a waste, no work is being accomplished
- When one process waits, the OS gives the CPU to another process
- The CPU scheduler selects a process from the processes in memory that are ready to execute and allocates the CPU to that process when the CPU becomes idle
- The process control block shows all the process' stuffs
- A preemptive scheme is when the OS can interrupt a running process and switch to another process before the current one finishes
- A nonpreemptive scheme is when scheduling takes place under 1 and 4, The CPU holds, The OS does not forcibly take the CPU away
- First know is to create the gantt chart and calculate the average wait time using each process when the algorithms used:
- First come first serve
- Shortest job first (preemptive and nonpreemptive)
- Round robin
- Then calculate exponential averaging using a formula
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.