Operating System Kernel, File System, and Linux Commands

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

Which of the following best describes the role of the kernel in a computer system?

  • It serves as the primary interface for networking and internet connectivity.
  • It directly manages user applications and their interfaces.
  • It acts as an intermediary between hardware and software, managing system resources. (correct)
  • It is responsible for compiling source code into executable programs.

Which of the following is NOT a typical function performed by a kernel?

  • Process management
  • Memory management
  • Web browsing (correct)
  • File system management

In a Linux filesystem, what does the root directory signify, and how is it represented?

  • The starting point for all files and directories, represented by a backslash `\`
  • The core of the operating system, represented by `.`
  • The top-level directory, represented by a forward slash `/` (correct)
  • The user's home directory, represented by `~`

Which of the following Linux commands is used to create a new directory?

<p>mkdir (A)</p>
Signup and view all the answers

What does sudo stand for in Linux, and what is its primary purpose?

<p>Super user do; to execute commands with elevated privileges. (B)</p>
Signup and view all the answers

In the context of compiling C code with gcc, what is the purpose of the -o option?

<p>It specifies the name of the output file. (A)</p>
Signup and view all the answers

From a program's perspective, how is memory typically viewed, and what is its address range in a 64-bit system?

<p>As a continuous array of bytes; address range is 0 to $2^{64}-1$ (D)</p>
Signup and view all the answers

Which memory section is used to store initialized global variables in a C program?

<p>DATA (A)</p>
Signup and view all the answers

What is stored in the 'Stack' memory section?

<p>Local variables and return addresses (B)</p>
Signup and view all the answers

In terms of memory growth, how do the heap and stack typically expand?

<p>Heap grows upwards, stack grows downwards (A)</p>
Signup and view all the answers

What is the likely outcome if a program attempts to access a memory address within a gap that has no memory mapping?

<p>The operating system sends a SEGV signal, typically terminating the program. (C)</p>
Signup and view all the answers

How do static libraries differ from shared libraries?

<p>Static libraries are included directly into the executable, creating a separate instance for each process, while shared libraries are loaded at runtime and shared across processes. (D)</p>
Signup and view all the answers

What distinguishes static events from dynamic events in programming?

<p>Static events happen during program building, while dynamic events occur while the program is running. (D)</p>
Signup and view all the answers

What is the consequence of an integer overflow in C, and how does C handle this?

<p>C performs two's complement arithmetic, causing the value to wrap around to the beginning of the value range. (C)</p>
Signup and view all the answers

What is the purpose of the & operator when used with a variable in C?

<p>It is used to access the memory address of the variable. (A)</p>
Signup and view all the answers

What is the function of the #include preprocessor directive in C?

<p>It includes header files or other source code files into the current file. (C)</p>
Signup and view all the answers

What is a ternary operator, and what symbols does it primarily use?

<p>A single-line conditional expression using <code>?</code> and <code>:</code>. (A)</p>
Signup and view all the answers

Why is a function prototype useful in C programming?

<p>It allows the compiler to check the correctness of function calls before the function is fully defined. (C)</p>
Signup and view all the answers

How does 'passing by value' differ from 'passing by reference' when passing arguments to a function?

<p>Passing by value creates a copy of the variable, while passing by reference allows the function to operate on the original data. (A)</p>
Signup and view all the answers

What is recursion, and how does a recursive function typically operate?

<p>A technique where a function calls itself to solve smaller instances of a problem. (A)</p>
Signup and view all the answers

Flashcards

What is the kernel?

The core of a computer system, managing hardware and software interactions.

Kernel Functions

A medium between hardware and software. Manages memory, processes, input/output, and file systems.

What is a File System?

A hierarchical structure for organizing files on a storage device. Root is represented by '/'.

What does 'sudo' stand for?

"Super User Do." Allows executing commands with elevated (administrator) privileges.

Signup and view all the flashcards

What is GCC?

It's a built-in compiler; Part of the GNU Compiler Collection; Compiles source code to machine code.

Signup and view all the flashcards

Program Memory View

A program sees memory as an array of bytes with an address range of 0 to 2^64 - 1.

Signup and view all the flashcards

Memory Sections

Memory is divided into sections: TEXT, DATA, BSS, STACK, HEAP, and Shared Libraries.

Signup and view all the flashcards

What is the Heap?

Space for dynamic memory allocation, grows upward in memory.

Signup and view all the flashcards

What is the Stack?

Stores local variables and return addresses; grows downwards in memory.

Signup and view all the flashcards

Program Address Space

Each program has an isolated view of memory.

Signup and view all the flashcards

Accessing a memory gap

Causes a SEGV signal which kills the program, dumping a core file.

Signup and view all the flashcards

Static vs. Shared Libraries

Static libraries are not shared, represented as (.a) files. Shared libraries are shared across processes.

Signup and view all the flashcards

What does #include do?

Includes preprocessor directives for libraries or files.

Signup and view all the flashcards

What does #define do?

Preprocessor directive used to create macros (constant values/expressions that are substituted before compilation).

Signup and view all the flashcards

What is a ternary operator?

A single-line if-else statement; uses ? and : symbols.

Signup and view all the flashcards

What is a function?

Blocks of code performing a specific task: Function declaration, definition, and call.

Signup and view all the flashcards

Function Prototype

Tells the compiler about the function's existence and its signature (return type, name, parameters).

Signup and view all the flashcards

Passing by value

Values are copied (new memory). Operates on a copy of the data.

Signup and view all the flashcards

Passing by reference

Allows operating on the original data. Modify the value of a variable in a function.

Signup and view all the flashcards

Recursion

Technique where a function calls itself to break down complex problems.

Signup and view all the flashcards

Study Notes

General Exam Information

  • The midterm is comprehensive
  • Review class labs and code, Zybooks material are excluded from the exam
  • Questions may involve code, but coding is not required
  • Understanding code operation and output will be tested
  • The exam consists of ~30 multiple choice and ~5 open ended questions

Lecture 1: The Kernel

  • It acts as the brain
  • It performs many functions within a computer system
  • It acts as a medium between hardware and software
  • It handles memory, process, input/output, and file system management

File System

  • It is represented as a tree
  • Root directory symbol: /
  • A file system manages file organization and access

Common Linux Commands

  • ls: Lists directory contents
  • cd: Changes directory
  • mkdir: Makes a new directory
  • mv: Moves files or directories
  • cp: Copies files or directories
  • scp: Securely copies files between hosts
  • tar: Archives files
  • rm: Removes files or directories
  • chmod: Changes file permissions
  • cat: Concatenates and displays files
  • grep: Searches for patterns in files
  • less: Displays file contents one page at a time
  • more: Displays file contents one page at a time (similar to less)
  • man: Displays the manual page for a command

Sudo

  • Stands for "Super User Do"
  • Used to execute commands with elevated privileges

GCC

  • It is a built-in compiler
  • Part of the GNU Compiler Collection
  • It compiles source code into machine code
  • Compilation command: gcc -o <output_file name> <source_file.c>
  • -o specifies the output file name

Lecture 2: Memory

  • A program views memory as an array of bytes ranging from 0 to 2^64 - 1
  • Organized into memory mappings

Memory Sections

  • TEXT: Stores the program's instructions
  • DATA: Stores initialized global variables
  • BSS: Stores uninitialized global variables (initialized to zero)
  • STACK: Stores local variables and return addresses
  • HEAP: Stores memory allocated by malloc/new
  • Shared Libraries: (.so files) are not included in the executable and are dynamically loaded at runtime

Heap and Stack

  • Heap: Allocates dynamic memory, grows upward in memory
  • Stack: Stores local variables, grows downwards in memory

Program Address Space

  • Each program has its own isolated memory view

Memory Gaps

  • Gaps may exist between memory sections without memory mappings
  • Attempting to access a memory gap triggers a SEGV signal, terminating the program and creating a core file

Static and Shared Libraries

  • Static Libraries: Not shared, each process has its own instance with .a files added to the executable
  • Shared Libraries: Shared across processes, only one instance exists for the entire system

Static and Dynamic Events

  • Static: Events during program building
  • Dynamic: Events during program execution

C Variable Types

  • int, char, double, pointer, string, float, short, long, unsigned

Integer Overflow

  • C handles it by using two’s complement
  • It wraps the value back to the beginning of the range.
  • Inputting 2,147,483,648 results in an output of -2,147,483,648

Lecture 3: Printf and Scanf

  • printf(): Prints variables and expressions to standard output (the terminal)
  • scanf(): Reads input from standard input (the console)

& Operator

  • It represents the address of a variable
  • It is used to get the memory address of a variable

Format Specifier for Printing

  • % (percent sign) is used for format specifiers in printing and scanning

#include

  • It declares preprocessor directives to include libraries or files

#define

  • Used to create macros
  • Macros are constant values or expressions that are substituted during compilation

Lecture 4: Ternary Operator

  • It is a one-line if-else
  • Uses ? and : symbols
  • ? acts as "then," : acts as "else."
  • variable = (condition) ? Expression2 : Expression3

Lecture 5: Functions

  • Functions: Code blocks for specific tasks
  • Composed of: declaration, definition, call
  • Function Prototype: Notifies the compiler of a function's existence and how to call it
    • If function is not defined before being called, the compiler will throw an implicit declaration warning
    • Using a function prototype resolves this issue
    • It provides the function's signature: return type, name, parameters

Passing by Value vs. Passing by Reference

  • Value: Copies the value to the function, creating new memory
  • Reference: Passes a reference allows the function to operate on the original data which modify values or avoid copying large data structures

Recursion

  • A function calls itself
  • Allows breaking down complex problems
  • Typically includes a base condition and a recursive call condition

Lecture 6: Pointers

  • Points to a memory address
  • Pointers size: 8 bytes on 64-bit systems and 4 bytes on 32-bit systems

Data Types and Pointers

  • Integer Size: 4 bytes
  • Character Size: 1 byte

Dereference Operator *

  • Accesses data at a memory address

Pointers Store

  • Memory addresses
  • int *ptr = &var
    • *ptr = &var: makes ptr point to the memory address of var
    • ptr: produces the memory address of var
    • *ptr: produces the value at the memory address of var

Pointer Arithmetic

  • (*ptr)++: Increments the value at the pointed address
  • *ptr++: Moves the pointer to the next memory address because unary operates read right to left

Double Pointer

  • Stores the memory address of another pointer
  • Useful for dynamic memory management

Array Decay

  • Occurs when an array is passed to a function
  • Array name decays into a pointer to the first element of the array
  • Only the memory address is passed, not a copy of the entire array

Array Size

  • It is needed to be passed as additional information in function

Sizeof()

  • Returns the total bytes of a type
  • It is used to calculate the size of an array: sizeof(array) / sizeof(array[0])

Passing Arrays

  • When passing an array becomes a memory address

Array Iteration

  • It is done via Pointer arithmetic
  • To iterate, a value is added to the pointer to move positions
  • Access data using *(ptr + 2)

Lecture 7: Stack

  • The stack stores information needed for control, data passing, and memory allocation
  • It holds local and temporary variables, arguments for the next function call, and return addresses

Stack actions

  • Push: Adds data
  • Pop: Removes data

Stack Management

  • Managed via the compiler
  • Creates one stack frame per function call
  • Stack frames are stacked on top of each other and destroyed at function exit

Stack Issues

  • Running out of stack space
  • Corrupting values
    • In other functions frames
    • In the function’s return address
  • Accessing memory after deallocation
  • Stack overflow
    • The program cashes

Buffer Overflow

  • Occurs when a program writes more data to a buffer than it can hold

Efficient Array Indexing

  • Pointers are more efficient than normal indexing

Malloc

  • Malloc dynamically allocates memory with a pointer
  • Returns a pointer that is stored in the heap

Pointer Cast Type

  • Requires a cast to the data type because malloc returns a void pointer

Pointer Size

  • The size of a pointer on a 32 bit system is 4 bytes

Lecture 8: Indexing

  • There are many equivalent ways
    • A[i] is equivalent to
    • *(a+i) which is equivalent to
    • *(&a[0]+i)

Deallocating Memory

  • The memory must be cleared by free() to prevent memory leaks

Problems

  • If memory is not deallocated then memory leaks can occur

Lecture 9/10 Heaps

  • When the heap runs out of space malloc returns 0
  • There can be changes to other heap data
    • Or data clobber which is data that gets overwritten
  • Memory can be accessed after it is freed, or freed twice
  • Freeing memory twice lead to crashing or corruption
  • Memory leaks can occur

Lecture 11: Common Frees

  • Premature frees: when an object still in use is freed
  • Double free: freeing an already freed object
  • Wild frees: freeing a pointer not returned by malloc
  • Memory smashing: allocating less memory than needed
  • Memory fragmentation: insufficient contiguous memory despite enough aggregate memory

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Cs 101 ( Module 51-60)
10 questions
Operating System Fundamentals Quiz
21 questions
Operating System: Components, Functions and Types
24 questions
Operating Systems Midterm Prep
43 questions
Use Quizgecko on...
Browser
Browser