Need to know for final

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

1/118

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.

119 Terms

1
New cards

What is a system call?

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

2
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.

3
New cards

What is the flow of a system call?

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

4
New cards

What are common use cases for system calls?

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

5
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.

6
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

7
New cards

What headers in C provide wrappers for system calls?

Headers like <unistd.h> and <fcntl.h> provide wrappers for system calls.

8
New cards

What is the role of errno in system calls?

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

9
New cards

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

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

10
New cards

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

On success, read() and write() return the number of bytes read or written, respectively. On error, they return -1.

11
New cards

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

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

12
New cards

What does close() return on success?

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

13
New cards

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

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

14
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.

15
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.

16
New cards

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

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

17
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.

18
New cards

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

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

19
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.

20
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.

21
New cards

What is the significance of system calls in user programs?

Without system calls, user programs cannot interact meaningfully with hardware.

22
New cards

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

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

23
New cards

What is the root directory in Linux?

/, which is the top of the hierarchy.

24
New cards

How are files organized in Linux?

Files are organized into a tree-like hierarchy starting at the root.

25
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).

26
New cards

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

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

27
New cards

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

It checks permissions and returns a file descriptor.

28
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.

29
New cards

What are the three categories of permissions in Linux?

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

30
New cards

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

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

31
New cards

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

You cannot open the file—you need permission.

32
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).

33
New cards

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

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

34
New cards

What is the definition of a network?

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

35
New cards

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

They are examples of device files.

36
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.

37
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.

38
New cards

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

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

39
New cards

What is the role of the kernel in file permissions?

The kernel checks file permissions before allowing reading or writing.

40
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.

41
New cards

What is a local network example?

A local network can be a home Wi-Fi.

42
New cards

What is the internet described as?

The internet is a network of networks.

43
New cards

Why is structure important in networking?

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

44
New cards

What is the solution to the challenges in networking communication?

Use a structured model to separate concerns into layers, where each layer has its own role and communicates only with its neighbors.

45
New cards

What is the OSI Model and how many layers does it have?

The OSI Model (Open Systems Interconnection Model) is a theoretical framework that describes how data moves through a network, from one computer to another, in seven layers.

The OSI Model has 7 layers: Application, Presentation, Session, Transport, Network, Data Link, and Physical.

46
New cards

What are the layers of the TCP/IP Model? And what is the TCP/IP Model?

The TCP/IP Model has 4 layers: Application, Transport, Internet, and Network Access.

The TCP/IP Model (Transmission Control Protocol/Internet Protocol model) is a practical networking model that describes how data travels across networks like the internet. It’s based on real protocols used every day.

47
New cards

What is network communication?

Network communication is how computers send and receive data over a network like the internet or Wi-Fi.

48
New cards

What is an IP Address?

An IP address (Internet Protocol address) is like the home address for a computer or device on a network.It tells other devices where to find it and how to send data to it. (e.g., 192.168.1.5).

49
New cards

What is a Port Number?

A Port Number is like an apartment number inside your device, helping to send data to the right program (e.g., web browser uses port 80 or 443).

50
New cards

What are packets in networking?

Packets are small chunks of data that include the data itself and address information.

51
New cards

What are protocols in networking?

Protocols are sets of rules for how devices communicate (e.g., TCP for reliable communication, UDP for fast but unreliable communication).

52
New cards

What is the role of a Client and Server in networking?

The Client starts the conversation (like a browser), while the Server waits and responds (like a website).

53
New cards

What is a socket in networking?

A socket is a tool in your program that opens a connection, similar to a phone line between two applications.

54
New cards

What is the TCP Handshake?

The TCP Handshake is a 3-step process to establish a safe connection: SYN → SYN-ACK → ACK.

55
New cards

What does a router do in networking?

A router sends data between networks, and NAT allows multiple devices to share one internet address.

56
New cards

What is encapsulation in networking?

Encapsulation means wrapping data and code together so that the details are hidden and protected from outside access.

57
New cards

What are the key features of TCP (Transmission Control Protocol)?

TCP is connection-based, ensures complete and ordered delivery, retransmits lost data, and checks for errors.

58
New cards

What are some examples of TCP in use?

Examples include web browsing (HTTP/HTTPS), email (SMTP), file transfers (FTP), and remote login (SSH).

59
New cards

What are the characteristics of UDP (User Datagram Protocol)?

UDP is connectionless, faster, does not guarantee delivery or order, and has no error correction.

60
New cards

What are some examples of UDP in use?

Examples include video calls (Zoom, FaceTime), online gaming, live streaming, and VoIP.

61
New cards

How does socket programming in C work?

A socket is a software object that allows programs to send and receive data over a network, defined by an IP Address and Port Number.

62
New cards

What analogy can be used to explain how a socket works?

A socket can be compared to a phone line, where dialing a number is like using an IP address and port, and opening a line of communication is like establishing a socket.

63
New cards

What are the initial steps to create a server-side socket?

1. Create a socket using socket().

2. Bind it to an IP and port using bind().

3. Listen for incoming connections using listen().

4. Accept a connection from a client using accept().

5. Send/receive data using read(), write(), recv(), or send().

6. Close the connection using close().

64
New cards

What are the initial steps to create a client-side socket?

1. Create a socket using socket().

2. Connect to the server using connect().

3. Send/receive data using read(), write(), recv(), or send().

4. Close the socket using close().

65
New cards

Why are sockets important in network programming?

Sockets are the foundation of all networked programs, enabling communication across any network such as LAN, Wi-Fi, or the internet, and are used in web browsers, games, chat apps, and servers.

66
New cards

What is multithreading?

Multithreading is running multiple parts of a program (threads) simultaneously within a single process, allowing independent execution while sharing the same memory space.

67
New cards

What is an analogy used to explain multithreading?

A restaurant kitchen: one chef represents single-threaded (slow), while many chefs represent multithreaded (faster, tasks in parallel).

68
New cards

What is a race condition in multithreading?

A race condition occurs when two threads access and change shared data simultaneously, leading to unpredictable or incorrect output.

69
New cards

How can race conditions be fixed?

By using locks or mutexes to ensure that only one thread can access shared data at a time.

70
New cards

What is deadlock in multithreading?

Deadlock occurs when two or more threads wait on each other indefinitely, never releasing resources.

71
New cards

How can deadlocks be prevented?

By locking resources in a consistent order.

72
New cards

What is livelock in multithreading?

Livelock occurs when threads keep reacting to each other but do not make progress.

73
New cards

How can livelock be addressed?

By adding delays or implementing smarter coordination.

74
New cards

What is starvation in multithreading?

Starvation happens when one thread never gets CPU time because others are prioritized.

75
New cards

How can starvation be mitigated?

By using fair scheduling or adjusting thread priorities.

76
New cards

What is context switching overhead?

Context switching overhead refers to the wasted CPU time that occurs when threads are frequently switched.

77
New cards

How can context switching overhead be minimized?

By limiting unnecessary switching and grouping tasks accordingly.

78
New cards

What is cache coherency in multiprocessor environments?

Cache coherency issues arise when CPU cores have outdated local copies of shared data.

79
New cards

How can cache coherency be resolved?

By using atomic operations or memory synchronization.

80
New cards

What is non-determinism in multithreading?

Non-determinism is when a program behaves differently on each run due to thread timing.

81
New cards

How can non-determinism be managed?

By testing carefully and using thread debugging tools.

82
New cards

What happens when you call pthread_create()?

The OS allocates memory for a new thread, and the CPU scheduler decides which thread runs on which core.

83
New cards

What is a lock (mutex) in programming?

A lock is a synchronization tool that ensures only one thread can access a shared resource or critical section at a time.

84
New cards

Why do we need locks in multithreaded programs?

Locks prevent threads from interrupting each other, corrupting data, and causing bugs like race conditions.

85
New cards

What are the general steps for using locks?

1. Initialize the lock.

2. Lock before accessing shared data.

3. Unlock after finishing.

4. (Optional) Destroy the lock when done.

86
New cards

What can happen without locks in multithreading?

Multiple threads may read and write simultaneously, leading to race conditions and data corruption.

87
New cards

TCP (Transmission Control Protocol)

A connection-oriented, guaranteed-delivery

protocol used to send data packets between computers over a network like the Internet.

88
New cards

UDP (User Datagram Protocol)

connectionless protocol that does not require a connection to send a packet and does not guarantee that the packet arrives at its destination

89
New cards

File Operations

open(), read(), write(), close()

90
New cards

Process control

A process is a program that is running. When you run a C program, it becomes a process.

Some of the functions include:

fork(): Creates a new process (a child process)

exec(): eplaces current process with a new program

wait(): Waits for a child process to finish

exit(): Ends the current process

91
New cards

Network I/O

socket(), connect(), bind()

92
New cards

Structures in C definition

A structure (or struct) in C is a user-defined data type that allows you to group different types of variables under one name.

93
New cards

File behavior definition

File behaviors describe how a file acts or changes during different operations—like opening, reading, writing, appending, seeking, or closing—based on how it was opened and used.

This includes:

Modes of access

Positioning inside the file

Overwriting vs appending

Buffering

Error handling

94
New cards

What is the purpose of fseek() in file behavior?

It moves the file pointer to a new position in the file (start, current, or end).

95
New cards

What does ftell() do?

tells you the current position of the file "cursor" (file pointer) in a file stream that you're working with using FILE *(opened with fopen()).

Think of it as asking:"Where am I in the file right now?"

96
New cards

What is buffering in file I/O?

Temporary storage in memory that holds data before it's written to disk for performance.

97
New cards

What happens if you don't call fclose()?

Data in the buffer may not be saved, and memory or file descriptors may be leaked.

98
New cards

What function is used to force data from the buffer to the file?

fflush(file);

99
New cards

What does perror() or strerror(errno) help with?

Displaying human-readable error messages when file operations fail.

100
New cards

What happens when writing to a file opened with "w" mode?

The file is cleared and overwritten from the beginning.