Purdue CS 252 Midterm Exam Q&A: Memory, Libraries, and System Architecture, Exams of Information Technology

A comprehensive set of questions and answers related to purdue's cs 252 midterm exam, covering essential topics in computer architecture and operating systems. It includes key concepts such as memory sections (text, data, bss, heap, stack), dynamic libraries, program building steps, memory allocation policies, fragmentation, and file systems. The material is designed to help students review and reinforce their understanding of fundamental computer science principles, offering clear explanations and practical insights into system-level operations. This study guide is useful for exam preparation and deepening knowledge in computer systems. (415 characters)

Typology: Exams

2024/2025

Available from 07/29/2025

Classhero
Classhero 🇺🇸

3.8

(4)

6.2K documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PURDUE CS 252 MIDTERM QUESTIONS AND ANSWER
What are the different types of memory sections? - -
Answers -Text
Data
BSS
Heap
Stack
What is stored in text? - -Answers -Instructions that run
the program.
What is stored in Data? - -Answers -Initialized global
variables
What is stored in BSS? - -Answers -Uninitialized global
variables (initialized to 0 by default)
What is stored in the heap? - -Answers -Memory that
was returned by malloc/new. It grows as you request
more. [grows upwards]
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Purdue CS 252 Midterm Exam Q&A: Memory, Libraries, and System Architecture and more Exams Information Technology in PDF only on Docsity!

PURDUE CS 252 MIDTERM QUESTIONS AND ANSWER

What are the different types of memory sections? - - Answers -Text

Data

BSS

Heap

Stack

What is stored in text? - -Answers -Instructions that run the program.

What is stored in Data? - -Answers -Initialized global variables

What is stored in BSS? - -Answers -Uninitialized global variables (initialized to 0 by default)

What is stored in the heap? - -Answers -Memory that was returned by malloc/new. It grows as you request more. [grows upwards]

What is stored in the stack? - -Answers -Local variables and return addresses. [grows downward]

What are dynamic libraries? - -Answers -They are libraries shared with other processes. Each have their own text, data, bss.

What is a program? - -Answers -File in a special format that contains all necessary information to load and application and make it run.

What are some examples of executable file formats? - - Answers -ELF - Executable Link File (Linux)

COFF - Common Object File Format (Windows)

What are the different steps to build a program? - - Answers -Editor, C preprocessor, Compiler, Optimizer, Assembler, Linker, Loader

What does the preprocessor do? - -Answers -Expands macros like #define and #include to generate a .i file.

What kind of free list did we use in the malloc lab? - - Answers -Segregated free list, which was a collection of free lists for various sizes.

What are the two different allocation policies? - -Answers -First fit [faster] (use the first chunk that satisfies the request), or Best Fit [less space] (choose the smallest chunk).

What is external fragmentation? - -Answers -Small non- contiguous block collect such that they cannot satisfy the request, thus wasting space.

What is the external fragmentation equation? - -Answers -% = 100 * (1 - (size_of_largest_block/total_mem_in_free_list))

What is internal fragmentation? - -Answers -Waste of memory due to the allocator returning a larger block than the memory requested.

What is the internal fragmentation equation? - -Answers -% = 100*(1-(size_request/mem_allocated))

What is stored in the header? - -Answers -Size, Left Size, Allocation Status, then either left/right pointers (if in free list) or data to point to the first free memory.

Total Size = 40 Bytes

Why use boundary tags? - -Answers -Allow for constant time coalescing since you can see if the left and right objects are free in O(1) time.

What are the different types of memory allocation errors?

  • -Answers -Memory Leaks, Premature Frees, Double Free, Wild Frees, Memory Smashing

What causes memory leaks? - -Answers -Leaks are objects in memory that are no longer being used but are not freed. Worse for 24/7 programs where they can accumulate quickly.

Object * obj = new Obj();

...

obj = new Object() // old object is leaked

What is an operating system? - -Answers -An OS is a program that sits in between the hardware and the user program.

What kind of file system does UNIX have? - -Answers - Hierarchical file system

What are some important directories? - -Answers -/ - Root Directory

/etc - OS Config files (passwd, groups)

/dev - List of devices attached

/usr - Libraries and tools

What is a deamon? - -Answers -Programs running in the background implementing a service (server).

What is root? - -Answers -User with special privileges to modify files anywhere in the system.

What are the yellow pages? - -Answers -In some systems, password and group files are stored in a server that makes management easier.

How are partitions divided? - -Answers -Boot Block, Superblock, Inode-list, Data Block

What is in the boot block? - -Answers -Block with small piece of code that tells the partition the OS is going to start.

What is in the super block? - -Answers -Gives you info about number of data blocks, number of Inodes (files), plus a bitmap about used/free Inodes and blocks.

What is in the data block? - -Answers -The location of the data of a file.

What is in the Inode list? - -Answers -Lise of inodes, which has informaiton about the file and what blocks make the file. One Inode per file.

What is an Inode? - -Answers -Represents a file (but can be a directory).

How is a directory represented? - -Answers -File that contains list of pairs, (file name, Inode number).

What is a hard link? - -Answers -Connection between file name and Inode number). If file is renamed, link will stay.

What is a soft link? - -Answers -Pair: (file name, inode number-with-file-storing-path). Like shortcuts, can point to files in different partitions. No reference count, no increment/decrement. If file is renamed, link will break

When does UNIX time start? - -Answers -0:00 Jan 1, 1970

How are the permission bits separated in UNIX? - - Answers -user group other

rwx rwx rwx

How do you change the permission bits? - -Answers - chmod <u|g|o><+|-><r|w|x> filename

How to change bits on octal? - -Answers -RWX RWX RWX

chmod 664 hello.c

Makes file readable and writable by everyone.

What is a directory bit? - -Answers -File flag that indicated if the file is a directory. When a directory, the x flag determines if it can be listed.

What properties does a process have? - -Answers -PID: Index in process table

Command and Arg

Env Variables

Current Dir

Owner (UserID)

Stdin/out/err

What is a process id? - -Answers -A PID is an integer that uniquely identifies processes among all live ones.

cp file1 file2 ... dest

Flags:

-R (recursively copy)

What does mv do? - -Answers -Move a file to a destination.

mv a.txt dir

(move a to dir)

mv a.txt b.txt

(rename a to b)

What does rm do? - -Answers -Removes a file.

Flags:

-f (hide error messages)

-R (recursive)

What does grep do? - -Answers -Prints lines that contain a pattern.

What does man do? - -Answers -Prints the manual page related to that command

Flags:

-s (specify section)

-k (all pages that contain word)

Sections:

  1. UNIX commands
  2. System Calls
  3. C Std Lib

What does whereis do? - -Answers -Prints the path of where a file is located.

What does which do? - -Answers -Prints the path of the command that will be executed if "command" is typed.

which ps

/usr/ucb/ps

Replaces all instances of current to new and redirects output to hello2.sh

What does find do? - -Answers -Recursively descend directories seeking files that match an expression, then executed command on them.

What is a shebang? - -Answers -Code at top of the file that says which shell will be executing the script.

#!/bin/bash

What does a parser do? - -Answers -Reads a command line and creates a command table. One entry corresponds to a component in the pipeline.

What does an executor do? - -Answers -Creates a new process for each row in the table, also creates pipes to communicate input/output

What does the open file table do? - -Answers -Any new file descriptor that gets created is added to the file table, hold info

[Inode, Open Mode, Offset, reference count]

What does fork() do? - -Answers -Creates a child process, the file table will also be copied, this incrementing the counts by 1.

What is the difference between exit() and _exit()? - - Answers -exit() flushes the buffer and runs atexit handlers. _exit() exits immediately without flushing any file buffers.

What is the Kernel Mode? - -Answers -When the CPU runs in this mode, it can execute any instructions. It can modify any location in memory, and can access or modify any of the registers.

What is the User Mode? - -Answers -When the CPU runs in this mode, it only has access to a limited set of instructions, and can only modify select sections of memory. The user program runs in user mode.

Page Faults (Virtual Memory page not loaded, invalid permission, etc)

Software Interrupts

What are system calls? - -Answers -Way user programs request services from OS.

Ex: open, read, write, fork

They are done in kernel mode because of special access and security.

What are the steps for the open system call? - -Answers -Get file name and mode

check if file exits

verify all permissions

ask disk to perform operation

wait

return fd

What happens if there is an error with the system call? - -Answers -The OS sets the global variable "errno" to the error number, can resolve with perror(s).

What happens if the user calls write(fd, buff, n) - - Answers -1. Write wrapper in libc generates a software interrupt

The OS interrupt handler checks the arguments. Verifies that the file is opened in write, also checks if range is valid.

OS tells the hard drive to write to the buffer.

OS puts process in wait mode until complete

Disk completes write and tells OS

Puts in back into ready state and it is scheduled to complete