CodeBlanks Logo Icon CodeBlanks

Summary - Kernel basics

Combine syscall and ioctl to write a system info tool.

Summary - Kernel basics

In this group you learned the boundary between the kernel and user programs: mode switching, system calls, ioctl for device control, the /proc virtual filesystem and dmesg logs.

Kernel services are always invoked through numbered syscalls. Devices are controlled with ioctl commands; /proc exposes state as text; dmesg shows the log buffer. Next you'll write a mini task that combines the five concepts. Move on to the code step when ready.

Practice Print kernel info

Define void print_kernel_info(const char *topic, const char *detail) with body printf("%s -> %s\n", topic, detail);. In main call it for five topics: ("kernel", "mode"), ("syscall", "trap"), ("ioctl", "device"), ("proc", "vfs"), ("dmesg", "log").

Starter code

main.c
#include <stdio.h>

// Define print_kernel_info function
// Print five topics: kernel, syscall, ioctl, proc, dmesg

int main(void) {
    return 0;
}

Sample solution

main.c
#include <stdio.h>

void print_kernel_info(const char *topic, const char *detail) {
    printf("%s -> %s\n", topic, detail);
}

int main(void) {
    print_kernel_info("kernel", "mode");
    print_kernel_info("syscall", "trap");
    print_kernel_info("ioctl", "device");
    print_kernel_info("proc", "vfs");
    print_kernel_info("dmesg", "log");
    return 0;
}

Expected output

kernel -> mode
syscall -> trap
ioctl -> device
proc -> vfs
dmesg -> log

What's next?

Congratulations! You've completed the kernel basics. You now know how a user program reaches the kernel: ask for services with syscall, control devices with ioctl, read state from /proc and watch logs with dmesg.

The next group moves to driver basics: loading kernel modules, logging with printk, device numbers with dev_t and the file_operations structure. It builds on what you learned here. Continue when you're ready.

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which is used to send a device-specific command?

  • printf
  • ioctl Correct answer
  • malloc
  • fopen

Explanation: ioctl carries device-specific commands.

2 Match the five concepts

Term Meaning
kernel Protected core
syscall Numbered service
ioctl Device command
proc Virtual filesystem
dmesg Log buffer

All lessons in Expert