CSC 3304 Final Review

0.0(0)
studied byStudied by 2 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/175

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

176 Terms

1
New cards

What is C?

A procedural, compiled language that all modern OSes are currently written in.

2
New cards

How do strings work in C?

They don't (technically)! Instead we have char[] or char*, arrays of characters

("hello" would be split into "h", "e", "l", "l", and "o")

3
New cards

What is null termination in C?

Strings must have one additional char accommodated, and have the last byte be 0x00 (escape sequence "\0"), otherwise standard functions will read past what's desired.

4
New cards

How do booleans work in C?

They don't (technically)! Instead we have 0 = false and !0 = true

(or if you REALLY want "true" and "false", import stdbool.h)

5
New cards

What are pointers in C?

An integer that "points" to the location of something in memory

6
New cards

What does & signify in pointers?

Gets the address of an operator

Ex. int X = 12; int* Y = &X = 5000

7
New cards

What does * signify in pointers?

Dereferences a pointer address to get what it's pointing to

Ex. int X = 12; int* Y = &X = 5000

Y = 5000 = 12 = X

8
New cards

How does pointer addition/subtraction work?

Adding/subtracting to a pointer increments/decrements the address's value by the data type's size (usually ints, so usually 4)

Ex. int* Y = 5000; Y + 1 = 5000 + (sizeOf(int)) = 5004

9
New cards

What is a segmentation fault?

when you try to resolve an invalid pointer

10
New cards

What is argc?

Argument COUNT; an integer that represents the number of arguments passed to the program from a command line

11
New cards

What is argv?

Argument VECTOR; an array of character pointers/strings that essentially contain the program's name and the arguments it has

12
New cards

What is a function stack?

A stack made up of stack frames, used to decide the order of functions being called

13
New cards

What is a stack frame?

An allocated space on a function stack for a single function. Stores variables and arguments needed

14
New cards

How are file permissions represented?

In order: Read (r), Write (w), and Execute (x)

Ex. rwx r-x r--

15
New cards

How are file types represented?

The first bit in a file permission string:

Regular file: -

Directory: d

Symbolic link: l

16
New cards

What are the file permission groups?

Increasing order:

User (owner),

Group (anyone matching the GID of the file),

World (any user)

17
New cards

What does > do?

Overwrites a file if it exists

Ex. [echo "Hello!" > Hello.txt] will either create Hello.txt or overwrite an existing file with the contents "Hello!"

18
New cards

What does >> do?

Appends to a file if it exists

Ex. [echo "Hello!" >> Hello.txt] will either create Hello.txt or append "Hello!" to an existing file

19
New cards

What do users in Linux generally have?

User ID (uid)

Group ID (gid)

Groups they belong to

A home path

A default shell

20
New cards

What does a root user have?

A user ID and group ID of 0, meaning they can essentially do anything

21
New cards

What are the /usr directories?

/usr: where user binaries (programs) and read-only data is stored

/usr/bin: user binaries

/usr/sbin: system admin binaries (addusr, cron, chpasswd)

/usr/lib: libraries for user binaries

22
New cards

What is /boot?

Contains all the programs and code needed to boot the OS

23
New cards

What is /etc?

Stores configuration files (program/boot configs, passwd and shadow, network configs...)

24
New cards

What is /dev?

Exposes device files, some of which can be used to communicate with hardware and some represent some utility

25
New cards

What is /proc?

Exposes device files, but kernel related

/proc/cpuinfo: exposes info about the cpu

/proc/slabinfo: exposes info related to the kernel memory manager

/proc/NUMBER: information about a running process

26
New cards

What is /home and /root?

Where all of the user's/root user's directories are stored, such as Documents, Downloads, Desktop, etc.

27
New cards

What is /lost+found?

A directory populated with corrupted files whenever Linux boots

28
New cards

What are /var, /tmp, and /run?

Readable and writable storage directories, where /var stores log files from running applications while /tmp and /run store temporary files

29
New cards

What is /opt?

A directory for optional packages, often third party software or software that doesn't conform to Linux storage conventions

30
New cards

What are /mnt and /media?

Directories for external media; /mnt mounts other file systems like external hard drives, while /media mounts removable media like flash drives or DVDs

31
New cards

What is a shell?

A command line interpreter that operates in a "current working directory"

32
New cards

What does the man command do?

Pulls up a manual for any command or function

33
New cards

What does the pwd command do?

Prints the directory your shell is currently operating under

34
New cards

What does the cd command do?

Changes your directory to another one

Ex. $ cd path -> changes your directory to the path

Ex. $ cd ../ -> moves one directory up

Ex. $cd ~ -> changes to your home directory

35
New cards

What does the ls command do?

Lists all of the files in a directory

36
New cards

What does the cat command do?

ConCATenate: prints the content of a file. The command "tac" also does this, but in reverse

37
New cards

What does the echo command do?

Displays a line of text in the command shell

38
New cards

What does the mkdir command do?

Makes a directory file

39
New cards

What does the rm command do?

Deletes a file at a path

40
New cards

What does the chmod command do?

Changes the file mode bits with a file. Two main ways to do it:

Ex. chmod +x myCode -> adds "executable" to myCode

Ex. chmod u=rwx,g=r,o= myCode -> directly changes owner, group, and world permissions

(You can also use numbers 0, 1, 2, and 4 as none, execute, write, and read permissions respectively)

41
New cards

What does the mv command do?

Moves a file by renaming a file's source to a destination

42
New cards

What does the cp command do?

Copies a file by copying a file at it's source into a destination

43
New cards

What does the find command do?

Searches for files on a system using different arguments:

-name: searches by name

-iname: searches by name, but case insensitive

-user: finds files owned by user

44
New cards

What does the strings command do?

Finds sequences of human readable characters. Can use -n to specify the minimum length

45
New cards

What does the uniq command do?

Removes or reports on duplicate lines in a file

46
New cards

What does the chown command do?

Changes ownership of a file

47
New cards

What does the less command do?

Opens up a file in a text viewer, where you use arrow keys to navigate, press / to pull up a text search, and press q to quit

48
New cards

What does the ln command do?

Creates a symbolic link, hard or soft

49
New cards

How does memory management work in C?

Make a call to malloc that gives a void pointer to the memory you requested, use that memory however you please, then free it once you're done

50
New cards

What does malloc() do?

Gets a pointer to an amount of memory using void * malloc(size_t size), where size is how large the memory is (usually obtained by sizeof(datatype))

51
New cards

What does calloc() do?

Allocates a block of memory using void* calloc(size_t nitems, size_t size), making a block large enough to hold all of the elements and initializes the memory to 0. Best for arrays

52
New cards

What does realloc() do?

Given a pointer previously allocated by malloc, calloc, or another realloc, it uses void realloc(void ptr, size_t size) to attempt to re-allocate a block in the requested size. If it succeeds, it returns a ptr to the new memory and frees the old memory. If it fails, it just returns null

53
New cards

What does free() do?

Takes a pointer allocated by malloc, calloc, or realloc and sets the memory free using free(void* ptr), allowing it to be overridden by future requests

54
New cards

What could go wrong with C memory management?

Memory leaks: failing to free memory allocated by malloc, often caused by losing a reference to a pointer

Null return: malloc may return a null ptr if it fails, and accidentally dereferencing it creates a seg fault

Use-after-free: Trying to use allocated memory after already using free() on it

Double-free: Trying to use free() on a pointer that's already been free()'d

55
New cards

What are some tips for C memory management?

-Ensure that every malloc() has a paired free() logically

-Be sure to avoid use of a pointer after it's been freed

-Always check for a null pointer

56
New cards

What is a stack in program memory?

Made up of static data allocations like local variables, function arguments, and return addresses. Memory is allocated in blocks within the stack, and it's automatically freed after execution finishes

57
New cards

What is a heap in program memory?

Made up of dynamic allocations like large data structures. Memory is allocated into heap memory that needs to be freed by a garbage collector after it's done being used

58
New cards

What is a system call?

how a user-space program requests a service from the kernel, such as reading from a file or creating new processes.

59
New cards

How does a system call work in C programming?

A C program calls a library function like read() or write(), which acts as a wrapper around a system call. Arguments are placed in CPU registers, a system call number is placed in register RAX, the CPU switches to kernel mode, the kernel performs the action, and then switches back to user mode.

60
New cards

What is the flow of a system call?

User Program → C Library → Registers Set → Kernel Mode → Action Done → Return to User.

61
New cards

What are common use cases for system calls?

File operations, process control, memory management, and network I/O .

62
New cards

What is a file descriptor?

A file descriptor (FD) is a non-negative integer that uniquely identifies an open file or other I/O resource in a process.

63
New cards

What are the common file descriptors in every program?

stdin (0) for standard input

stdout (1) for standard output

stderr (2) for standard error

64
New cards

What headers in C provide wrappers for system calls?

<unistd.h> and <fcntl.h>

65
New cards

What is the role of errno in system calls?

when a system call fails and is relevant only on failure, helping to diagnose what went wrong.

66
New cards

What does the open() system call return on success?

file descriptor (an integer). On error, it returns -1.

67
New cards

What do read() and write() return on success?

number of bytes read or written. on error, they return 0.

68
New cards

What does the socket() system call return on success?

On success, socket() returns a socket descriptor. On error, it returns -1.

69
New cards

What does close() return on success?

On success, close() returns 0; on error, it returns -1.

70
New cards

What is file I/O in the context of Linux systems?

allows a program to read from or write to files on disk, treating files as resources.

71
New cards

What is the hierarchy analogy for file I/O?

The disk is like a filing cabinet, directories are drawers, and files are folders.

72
New cards

What functions are used for high-level file I/O in C?

fopen() to open a file

fread(), fwrite(), fgets() for input/output

fclose() to close the file.

73
New cards

What are the benefits of using Unix system calls for file I/O?

work with file descriptors, providing more power and flexibility compared to high-level I/O functions.

74
New cards

What is the importance of checking return values in system calls?

Checking return values is crucial as -1 often indicates failure, allowing for error handling.

75
New cards

What does the term 'file I/O concepts and behavior' encompass?

how files are accessed, organized, and safely interacted with in a system that treats nearly everything as a file.

76
New cards

What is the analogy used to explain system calls?

The OS kernel is likened to a librarian who must be requested to fetch resources for the program.

77
New cards

What happens when a system call is made?

The CPU switches to kernel mode to perform the requested action and then switches back to user mode.

78
New cards

What is the significance of system calls in user programs?

the user programs can interact meaningfully with hardware.

79
New cards

What is the role of the C library in system calls?

provides functions that wrap around system calls, making them easier to use in programs.

80
New cards

What is the root directory in Linux?

/, which is the top of the hierarchy.

81
New cards

How are files organized in Linux?

tree-like hierarchy starting at the root.

82
New cards

What are the types of file paths in Linux?

Absolute paths (e.g., /home/user/notes.txt) and relative paths (e.g., ./notes.txt).

83
New cards

What are the types of files accessed through file I/O in Linux?

Regular files, directories, devices, pipes, and sockets.

84
New cards

What does the open system call do in file I/O?

It checks permissions and returns a file descriptor.

85
New cards

What is the difference between buffered and unbuffered I/O?

Buffered I/O (e.g., fread, fgets) stores data temporarily before processing, while unbuffered I/O (e.g., read, write) deals with data immediately.

86
New cards

What are the three categories of permissions in Linux?

Owner (user), group, and others (world).

87
New cards

What do the permission symbols 'r', 'w', and 'x' stand for?

'r' = read, 'w' = write, 'x' = execute.

88
New cards

What happens when you try to access a file without permission?

You cannot open the file—you need permission.

89
New cards

What is the difference between 'w' and 'a' modes in file operations?

'w' = write only (overwrites existing file), 'a' = append only (adds to existing file).

90
New cards

What does the 'r+' mode do when opening a file?

Opens the file for reading and writing; the file must exist.

91
New cards

What is the definition of a network?

a group of two or more computers connected so they can share information.

92
New cards

What is the significance of /dev/null and /dev/random in Linux?

They are examples of device files.

93
New cards

What is the purpose of the close system call in file I/O?

It frees the OS resource associated with the file descriptor.

94
New cards

What does the 'w+' mode do when opening a file?

Opens the file for reading and writing; will create or overwrite the file.

95
New cards

What does the 'a+' mode do when opening a file?

Opens the file for reading and writing; will append at the end.

96
New cards

What is the role of the kernel in file permissions?

checks file permissions before allowing reading or writing.

97
New cards

What does the term 'directories are files that list other files' mean?

Directories in Linux serve as containers that organize and list files within them.

98
New cards

What is a local network example?

home Wi-Fi.

99
New cards

What is the internet described as?

a network of networks.

100
New cards

Why is structure important in networking?

different devices, operating systems, and programs need to communicate, often using different hardware and software.