Showing posts with label Linux Kernel Programming. Show all posts
Showing posts with label Linux Kernel Programming. Show all posts

Thursday, November 5, 2020

Kernel Threads

  • kthreadd (pid = 2) created by kernel (pid = 0) during boot
  • kthreadd helps in creating other kernel threads which are required to run periodically/asynchronously
  • "ps" shows kernel threads
  • Everything under [square bracket] are kernel threads

sw0:FID128:root> ps -eaf
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 01:21 ?        00:00:00 init [5]
root         2     0  0 01:21 ?        00:00:00 [kthreadd]
root         3     2  0 01:21 ?        00:00:00 [ksoftirqd/0]
root         4     2  0 01:21 ?        00:00:00 [kworker/0:0]

  • All calls from user-space to create a new process (including "create_thread" in kthreadd), will end up in do_fork call which internally calls copy_process

Tuesday, December 4, 2012

Important Kernel Structures and its sizes

NOTE: The following are found in 32-bit Ubuntu system (Kernel version:  3.2.0-29-generic-pae)

1. Process kernel stack = 8KB in 32 bit; 16KB in 64 bit
Basically, 2 pages as process kernel stack

2. task_struct - structure for each process
sizeof(task_struct) = 3236 bytes = 3.1 KB

3. thread_struct - structure of thread info in each task_struct
sizeof(thread_struct) = 128 bytes

/proc File system usages

NOTE: The following are found in 32-bit Ubuntu system (Kernel version:  3.2.0-29-generic-pae)

1. [PID_MAX]:  default - 32768 (short int)
"/proc/sys/kernel/pid_max"

2. [Loadable Modules]
"/proc/modules" Used by "lsmod"

3. [printk levels]: default 7
echo "/proc/sys/kernel/printk"