3 ms·
Some nice archaeology here, but I think it's important to say "pid 0 is part of the [Linux] kernel" (much less the further details) is only useful from a certai
by scottlamb 2y ago
Some nice archaeology here, but I think it's important to say "pid 0 is part of the [Linux] kernel" (much less the further details) is only useful from a certain perspective—if you are debugging the kernel itself, using its more idiosyncratic interfaces like trace points within e.g. eBPF to examine the system as a whole, etc.
From the perspective of a userspace process using standard APIs, I think a more useful approximation is "pid 0 refers to myself". It's what fork returns in the child. It's what you pass in to kill(2) to signal your own entire process group. Probably other variations too.
- hi-v-rocknroll 2y agoThere is no PID 0, it's a ABI convention just as using a negative PID is a convention to use the PGID instead like kill -9 -1. PIDs start at 1. The Linux kernel allocates PIDs to kernel threads that are "processes" without a separate address space running in a privileged mode with separate stacks, and generally ignore kill() signals. Command to get when a Linux box was started as opposed to just running uptime -s: ps -p 2 -o lstart=
- scottlamb 2y agoOkay. I said approximation, and saying that the approximation is not completely true is not that interesting.
- wzdd 2y agoEven in your own examples 0 means different things. It’s not an approximation, it’s wrong.
- bvaldivielso 2y agoAll models are wrong, some are useful. I found his explanation useful while knowing it was not correct
- helpfulContrib 2y agoBut this statement is wrong and should not be propagated: "pid 0 refers to myself". pid 0 refers to the thing that is running 'myself', not to myself, itself. It is the thing which gave way to allow 'myself' to be executing in the current context. It is more accurate to say "pid 0 is the source of cpu 'attention' which allows myself 'awareness'", as it discovered I was not idle, and granted me power to proceed with processing ..
- echoangle 2y agoBeing slightly wrong is kind of the thing that makes an approximation an approximation
- mrits 2y agoI think generalization would have been a better word but everyone understands what they meant
- deleted 2y ago[deleted]
- usr1106 2y agoWhy not ps -p 1 -o lstart= ? In real life the difference should be rarely visible. And then, did we want to know when it started booting or when it became usable. The latter would be rather tricky (even defining what it exactly meant by that).
- deleted 2y ago[deleted]