Welcome back to our userspace-kernel communication topic! Let's dive into our recent progress and future steps. ✨
- Until now, a standalone API has been created to send messages from userspace to kernel space.
- The next target is to develop a full-fledged userspace program.
- The execution starts from the Main function.
- The immediate action is the creation of a netlink socket.
- The protocol number remains the same as before, which is
31
.
- The protocol number remains the same as before, which is
- The socket will then be bound. More on binding during code discussion.
- To facilitate simultaneous message sending and receiving, a separate thread will be initiated.
- The main thread is responsible for sending messages to kernel space.
- The separate receiver thread deals with incoming messages from the kernel.
- Enter the main menu.
- More options will be added as the program evolves.
- The first option, "Greet Kernel":
- Sends a text message to the kernel.
- Invokes the previously created API to send the netlink message.
- After sending, it returns to the main menu.
- This loop continues indefinitely.
- This thread is continuously active and listens for messages.
- Uses the blocking 'receive message' system call.
- Will remain inactive until a message is detected.
- Once a message is received:
- The program resumes execution.
- The message is processed.
- Returns to the 'receive message' state, waiting for the next message.
- The user space application operates with two threads.
- The main thread keeps sending messages.
- The receiver thread awaits and processes incoming messages.
Q1: What is the purpose of the standalone API developed earlier?
A1: The standalone API was developed to send messages from userspace to kernel space.
Q2: Why is the protocol number 31
significant in this context?
A2: The protocol number 31
is the reserved number used when creating the netlink socket both in the user space and kernel space.
Q3: What is the primary role of the separate receiver thread?
A3: The separate receiver thread's primary role is to continuously listen and process messages coming from the kernel space.
Q4: Describe the behavior of the 'receive message' system call in the receiver thread.
A4: The 'receive message' system call is a blocking call. The receiver thread will stay blocked on this call until it receives some data on the netlink socket.
Q5: How does the main thread function in relation to the main menu?
A5: The main thread enters the main menu where it offers options to interact with the kernel. After performing an action, such as sending a message, it returns to the main menu, and this continues in an infinite loop.
Good luck with your interviews! 🍀