1/118
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
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.
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.
What is the flow of a system call?
User Program → C Library → Registers Set → Kernel Mode → Action Done → Return to User.
What are common use cases for system calls?
File operations, process control, memory management, and network I/O .
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.
What are the common file descriptors in every program?
stdin (0) for standard input
stdout (1) for standard output
stderr (2) for standard error
What headers in C provide wrappers for system calls?
Headers like <unistd.h> and <fcntl.h> provide wrappers for system calls.
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.
What does the open() system call return on success?
On success, open() returns a file descriptor (an integer). On error, it returns -1.
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.
What does the socket() system call return on success?
On success, socket() returns a socket descriptor. On error, it returns -1.
What does close() return on success?
On success, close() returns 0; on error, it returns -1.
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.
What is the hierarchy analogy for file I/O?
The disk is like a filing cabinet, directories are drawers, and files are folders.
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.
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.
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.
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.
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.
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.
What is the significance of system calls in user programs?
Without system calls, user programs cannot interact meaningfully with hardware.
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.
What is the root directory in Linux?
/, which is the top of the hierarchy.
How are files organized in Linux?
Files are organized into a tree-like hierarchy starting at the root.
What are the types of file paths in Linux?
Absolute paths (e.g., /home/user/notes.txt) and relative paths (e.g., ./notes.txt).
What are the types of files accessed through file I/O in Linux?
Regular files, directories, devices, pipes, and sockets.
What does the open system call do in file I/O?
It checks permissions and returns a file descriptor.
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.
What are the three categories of permissions in Linux?
Owner (user), group, and others (world).
What do the permission symbols 'r', 'w', and 'x' stand for?
'r' = read, 'w' = write, 'x' = execute.
What happens when you try to access a file without permission?
You cannot open the file—you need permission.
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).
What does the 'r+' mode do when opening a file?
Opens the file for reading and writing; the file must exist.
What is the definition of a network?
A network is a group of two or more computers connected so they can share information.
What is the significance of /dev/null and /dev/random in Linux?
They are examples of device files.
What is the purpose of the close system call in file I/O?
It frees the OS resource associated with the file descriptor.
What does the 'w+' mode do when opening a file?
Opens the file for reading and writing; will create or overwrite the file.
What does the 'a+' mode do when opening a file?
Opens the file for reading and writing; will append at the end.
What is the role of the kernel in file permissions?
The kernel checks file permissions before allowing reading or writing.
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.
What is a local network example?
A local network can be a home Wi-Fi.
What is the internet described as?
The internet is a network of networks.
Why is structure important in networking?
Structure matters because different devices, operating systems, and programs need to communicate, often using different hardware and software.
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.
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.
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.
What is network communication?
Network communication is how computers send and receive data over a network like the internet or Wi-Fi.
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).
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).
What are packets in networking?
Packets are small chunks of data that include the data itself and address information.
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).
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).
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.
What is the TCP Handshake?
The TCP Handshake is a 3-step process to establish a safe connection: SYN → SYN-ACK → ACK.
What does a router do in networking?
A router sends data between networks, and NAT allows multiple devices to share one internet address.
What is encapsulation in networking?
Encapsulation means wrapping data and code together so that the details are hidden and protected from outside access.
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.
What are some examples of TCP in use?
Examples include web browsing (HTTP/HTTPS), email (SMTP), file transfers (FTP), and remote login (SSH).
What are the characteristics of UDP (User Datagram Protocol)?
UDP is connectionless, faster, does not guarantee delivery or order, and has no error correction.
What are some examples of UDP in use?
Examples include video calls (Zoom, FaceTime), online gaming, live streaming, and VoIP.
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.
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.
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().
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().
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.
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.
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).
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.
How can race conditions be fixed?
By using locks or mutexes to ensure that only one thread can access shared data at a time.
What is deadlock in multithreading?
Deadlock occurs when two or more threads wait on each other indefinitely, never releasing resources.
How can deadlocks be prevented?
By locking resources in a consistent order.
What is livelock in multithreading?
Livelock occurs when threads keep reacting to each other but do not make progress.
How can livelock be addressed?
By adding delays or implementing smarter coordination.
What is starvation in multithreading?
Starvation happens when one thread never gets CPU time because others are prioritized.
How can starvation be mitigated?
By using fair scheduling or adjusting thread priorities.
What is context switching overhead?
Context switching overhead refers to the wasted CPU time that occurs when threads are frequently switched.
How can context switching overhead be minimized?
By limiting unnecessary switching and grouping tasks accordingly.
What is cache coherency in multiprocessor environments?
Cache coherency issues arise when CPU cores have outdated local copies of shared data.
How can cache coherency be resolved?
By using atomic operations or memory synchronization.
What is non-determinism in multithreading?
Non-determinism is when a program behaves differently on each run due to thread timing.
How can non-determinism be managed?
By testing carefully and using thread debugging tools.
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.
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.
Why do we need locks in multithreaded programs?
Locks prevent threads from interrupting each other, corrupting data, and causing bugs like race conditions.
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.
What can happen without locks in multithreading?
Multiple threads may read and write simultaneously, leading to race conditions and data corruption.
TCP (Transmission Control Protocol)
A connection-oriented, guaranteed-delivery
protocol used to send data packets between computers over a network like the Internet.
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
File Operations
open(), read(), write(), close()
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
Network I/O
socket(), connect(), bind()
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.
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
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).
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?"
What is buffering in file I/O?
Temporary storage in memory that holds data before it's written to disk for performance.
What happens if you don't call fclose()?
Data in the buffer may not be saved, and memory or file descriptors may be leaked.
What function is used to force data from the buffer to the file?
fflush(file);
What does perror() or strerror(errno) help with?
Displaying human-readable error messages when file operations fail.
What happens when writing to a file opened with "w" mode?
The file is cleared and overwritten from the beginning.