Welcome to the Linux Foundation Forum!

What really is kthreadd (PID=2)?

In chapter 3, page 6 creating processes, the course states that kthreadd (PID=2) purpose is to adopt orphaned processes.

I'm running ArchLinux with kernel 5.13 and all the processes with PPID=2 as reported with ps axjf are reported in square brackets, i assume they are kernel threads?

I also see many processes with PPID=1 (/sbin/init, that is a symlink to systemd), for example tmux and ssh-agent have PPID=1. I was expecting them to be have kthreadd as the parent, not init.

So, when does init adopt a process and when does kthreadd adopts?

Is there a documentation/man about kthreadd somewhere? I could not find it.

Comments

  • coop
    coop Posts: 916

    If you examine the list you will see all [ ] processes have ppid=2 (kthreadd) while all user space processes may have ppid=1 (systemd/init). kthreadd is actually the internal kernel thread that is used in kernel code with functions like kthread_create() to create these kernel threads or adopt them. Perhaps the wording is not the best, I will investigate. thanks

    as far as documentation about kthreadd goes, http://www.tovantran.com/blog/?p=2591 is one simple (but dated) explanation,

  • Hi @coop,

    Thanks for the explanation and the link.

    There's also a similar statement in page 8 (Process States):

    If the parent of any process dies, the process is adopted by init (PID = 1) or kthreadd (PID = 2).
    

    Do you think it is possible to amend/update these pages with a clearer explanation about which process adopts orphans?

    Is there a place that I can suggest/submit changes?

Categories

Upcoming Training