I know when a task runs, it is enqueued into the running queue. When it sleeps, it is dequeued from the running queue. But is there a queue for sleeping tasks? I didn’t see this in the source code.
And even if I were to create such a queue, how can I know when a task is killed and should be removed from the sleeping queue?
Can anyone give me a hint? Thanks,
In Linux blocked (sleeping) tasks are queued in a structure called a wait queue. There exists a wait queue per event (or object) that can be waited upon.
So, there is no single wait queue (or per core), but per event wait queue. The kernel code explicitly puts tasks on the wait queue and removes them when the specific event arrives. See wait_event() kernel API for example.