return to table of content

What Is PID 0?

caseyy
11 replies
18h8m

People are far overconfident online for what they know. The definitive and confident tone most online commenters speak in should probably only be spoken by experts in their own fields.

I sometimes wonder if that is why LLMs can so confidently hallucinate — because they were trained on piles of overconfident human texts.

It's an interesting thing to ponder.

ultra_nick
8 replies
17h41m

People should be suspicious of statements regardless of tone. Conmen, hackers, cult members, job applicants, and AIs are all trying to trick people who only listen to tone.

caseyy
7 replies
17h37m

It takes a lot of cognitive work to doubt and analyze everything. It's not really feasible, is it?

ilc
3 replies
16h41m

Review enough code, and even 2 + 2 can look sus.

Where's the operator overload? ;)

tinyhitman
2 replies
7h47m

In the garbage language that we dont use anymore. Right? Right!? :)

smitty1e
0 replies
3h7m

Unfortunately, due to budget cuts, we could not afford to vanquish all of the antiques in the architecture. We do have an infinite spell of Ben Gay, however....

kevindamm
0 replies
3h32m

well yeah but there's that legacy system, the replacement isn't ready for GA yet so...

n4r9
0 replies
8h33m

As with many things, it becomes easier with practise. Also, you can pace accordingly: do I quickly read 10 articles today, or pick 2 and peruse them in depth?

autoexec
0 replies
11h6m

It's also not really necessary a lot of the time. If some random person online confidently says that the newest tesla uses an engine which contains ball bearings made in Indonesia by child slaves, I don't have to spend the time to doubt and analyze that because it doesn't impact me personally. I'd only ever need to take the time to double check that if I were going to buy a tesla or before I went and spread that information around as if it were fact. How true or false it is doesn't affect my life in any way. It can just be something a random person said online and I can treat it as such.

Whenever you see information that sounds like it could be extremely important to you and your situation (and when being wrong could really hurt you) then no matter how authoritatively the information was delivered that's really when you should invest the time to verify it. Much of the time that investment is just a quick internet search anyway.

Bjartr
0 replies
5h18m

So safe the effort for the things that actually matter in your life.

brightlancer
1 replies
3h57m

People want to listen to folks who are confident.

And that sentence right there is an example of what I mean. I could write 10 words, 100 words or 1,000 words adding caveats to "People want to listen to folks who are confident," but most people don't want to hear it and they'd tune out. But nine words, they'll listen to and use that, even if it's not right all the time.

This isn't just an "online" issue. Anecdotally, I'd say it's in human nature. I've read plenty lamenting how men are (over)confident at work and garner (unwarranted) success relative to less confident women. And IME, confidence at work is pretty successful, if only because folks _try_ the confident suggestion. The person with a host of caveats might have a better suggestion, but they are less confident in their result, which folks sense and shy away from.

And then there are casual situations (which most of "online" discourse is), where I regularly see strangers confidently offer one another advice which is usually received positively. A lot of the advice is wrong, but that doesn't really matter.

I sometimes wonder if that is why LLMs can so confidently hallucinate — because they were trained on piles of overconfident human texts.

The LLMs that I have worked with have no concept of "true" and "false". They have no sense of confidence in what they sense.

They _phrase_ it definitively because that's what we want.

"What is the capital of Australia."

"The capital of Australia is Timbuktu."

The LLM doesn't know if that's true. It's just making a statement we asked it to make.

maxrecursion
0 replies
2h4m

There is a reason con man is short for confidence man.

People are extremely susceptible to someone who sounds confident.

scottlamb
7 replies
19h23m

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
6 replies
17h42m

There 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
5 replies
16h37m

Okay. I said approximation, and saying that the approximation is not completely true is not that interesting.

wzdd
4 replies
16h20m

Even in your own examples 0 means different things. It’s not an approximation, it’s wrong.

bvaldivielso
1 replies
10h48m

All models are wrong, some are useful. I found his explanation useful while knowing it was not correct

helpfulContrib
0 replies
10h16m

But 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 ..

mrits
0 replies
5h3m

I think generalization would have been a better word but everyone understands what they meant

echoangle
0 replies
8h54m

Being slightly wrong is kind of the thing that makes an approximation an approximation

amelius
4 replies
5h11m

When I type "ps -aux", why do I get all the information from other users too? Shouldn't this be private information by default?

amelius
0 replies
4h57m

My point: why isn't this private __by default__?

(Also, I fear that by setting this flag it will break a lot of tools that expect the flag to be 0)

GranPC
1 replies
5h6m

It's configurable - "hidepid=1" mount option on procfs.

hxelk1
0 replies
5h0m

Careful, this won't stop systemctl from showing the full process command line in its output.

kazinator
2 replies
4h35m

Wow, this entire article is completely off the mark.

0 is a special value in the POSIX kill function. It denotes every process in the process group of the caller.

That's it.

(OK, so because of that, a given OS based on POSIX can internally get away with using the value in some ways, to denote some process that nothing in user space would ever know about, let alone try to send a signal to.)

Don't get nerd-sniped! Know the 15 second answer and move on.

Karellen
1 replies
4h13m

Maybe it was only used as the `all in progress group` sentinel because it was used by the kernel and could never be the pid of a userspace process?

There's no reason that Unix couldn't have defined `PID_ALLPROCGRP = -2` instead.

I mean, what do you think came first the development of Unix? The pid taken by the kernel thread used for scheduling, or a special value to a syscall when someone realised "hey, maybe being able to kill the entire process group would be handy. What spare values do we have we can use to indicate that?"

(And remember, POSIX codified existing practice. Unices don't use pid 0 for a reason because POSIX says so; POSIX says so because that's what Unices did)

kazinator
0 replies
28m

Maybe it was only used as the `all in progress group` sentinel because it was used by the kernel

Ah, but for that we have to long beyond/before Linux. kill(0, signal) existed before a line of Linux was written.

Linux followed the existing POSIX spec which gave it PID 0 to do whatever.

fragmede
2 replies
8h4m

Why not just edit wikipedia to be correct?

lelandfe
1 replies
6h25m

I’d love to go edit the Wikipedia article and set the record straight… But would that count as “primary research”? Would the edit be reverted because it disagrees with most of the web? Does publishing this post mean editing wikipedia would now count as some variation of sockpuppeting or self-promotion?
immibis
0 replies
2h53m

Wikipedia has now been edited, citing this blog post as a source.

Him editing Wikipedia to include his own research is "primary research". Him editing using his own blog post as a a citation is presumably self-promotion. But someone else editing it in seems okay.

userbinator
1 replies
15h31m

On NT-based Windows, PID 0 is "System Idle Process" and is quite similar in function to the Linux one. On DOS-based Windows, IIRC there is no such thing as PID 0 since PIDs there are actually kernel memory pointers and thus very high: http://www.thescarms.com/VBImages/RunningProcs.gif -- instead, the idle loop is inside VMM32.

therein
0 replies
10h40m

Having written some code that did some DKOM in Windows, I'd say PID 4 comes closer.

thayne
1 replies
14h21m

It seems like TID would be a better term for the in-kernal concept of a "pid", which could stand for "task id" or "thread id", whichever you prefer. And wouldn't be as confusing.

lionkor
0 replies
11h56m

And afaik that is sometimes a thing via gettid()

nickelpro
1 replies
7h40m

PID 0 on most academic Unixs used for teaching operating system design still swap out the entire process, and call into the memory subsystem ("paging") to do so.

Linux is not the owner of the concept of PID 0. Saying that PID 0 frequently is involved with paging in and out memory is not incorrect.

fanf2
0 replies
1h25m

I checked xv6 and it doesn’t swap out processes. What teaching OSs are you thinking of?

naleshniki
1 replies
7h23m

I agree with the author's complaint about the problems of Wikipedia being taken as authoritative on operating systems. I have seen all kinds of bizarre claims which are at odds with reality, but which, being described in a wikipedia page, are taken for gospel, and end up reproduced and sometimes embellished further.

His article is probably quite a good discussion of what happens on Linux. It is over-reaching however if it is supposed - as it seems to be in the conlusions - to be talking about modern Unix-likes generally.

PID 0 on NetBSD (and I suspect of Free, DragonFly, Open, etc, as well) simply means the kernel process. Here are a few of the threads that run under the kernel process in NetBSD:

  PID PPID CPU LID NLWP PRI NI   VSZ   RSS WCHAN    STAT TTY     LTIME COMMAND
    0    0   0 118  106 123  0     0 28132 physiod  DK-  ?     0:00.00 [system]
    0    0   0 117  106 125  0     0 28132 pooldrai DK-  ?     0:00.00 [system]
    0    0   0 116  106 124  0     0 28132 syncer   DK-  ?     0:00.00 [system]
    0    0   0 115  106 126  0     0 28132 pgdaemon DK-  ?     0:00.00 [system]
These are all true and authentic threads, they just don't spend any time executing userland code. The work they carry out is, respectively: to carry out I/O to/from buffers in userland, because this may incur page faults and cannot therefore be done in a soft interrupt which has no thread context; to reclaim pages from the pool (slab) allocator; to lazily synchronise dirty buffers back to disk; and to carry out page replacement.

All of these listed above carry out memory management, so it is not correct to say that PID 0 "has nothing to do with memory management" or that the Wikipedia article is wrong to discuss paging as a responsibility of PID 0. That's what pgdaemon is doing!

There are many other threads that are part of the kernel process (or "PID 0") on NetBSD - modern kernels generally use a lot of them to carry out all sorts of tasks. A few others on NetBSD include worker thraeds for running asynchronous I/O completions and for processing various kinds of input in the networking stack.

Illumos should also be considered. Looking at its PID 0:

      root     0     0     1     1   0 11:22:53 ?           0:02 sched
We can see it is called sched. Why sched? This article talked about the historic role of PID 0 in process swapping. Process swapping is a scheduling problem (like a lot of problems in software). This is why swappers are traditionally called medium-term or memory schedulers. Illumos generally gives most groupings of kernel worker threads their own processes with their own PIDs, but one, called "sched", remains in PID 0, and its responsibility? Process swapping:

https://github.com/illumos/illumos-gate/blob/579c23696ac6891...

The Wikipedia article has now been hastily edited, and replaces a claim that was true only of certain Unixes other than Linux with a claim true only of certain Unixes including Linux. Is this an improvement?

wizzwizz4
0 replies
3h3m

I have seen all kinds of bizarre claims which are at odds with reality, but which, being described in a wikipedia page, are taken for gospel, and end up reproduced and sometimes embellished further.

Editing Wikipedia is fun, but sometimes it is hard to know where to edit. Here's a simple process to find correctable errors!

(1) Sneak onto your local university's campus.

(2) Sit in any operating systems lecture.

(3) Watch for nonsense in the slides.

(4) Locate the relevant Wikipedia page.

(5) Rewrite the entire two-page section around whatever was on that slide, because chances are it's all nonsense.

Ferret7446
1 replies
17h36m

Kind of clickbait/misleading title? The article even states that PID is a userspace concept. There is no PID 0. PIDs is how userspace refers to processes in syscalls. You can't refer to a PID 0 because `kill(0)` has a special meaning.

But "What is TGID 0?" is much less catchy of a title. Hence, clickbait.

singron
0 replies
15h13m

Specifically, kill()ing pid 0 kills every process in the process group of the calling process. Pid 0 is more like a NULL pointer. You can put something in memory there, but a lot of systems will treat it as an invalid identifier for their own purposes.

I had some ruby code that called kill(str.to_i) and killed every process when the string wasn't an integer, which is when I painfully found out that to_i returns 0 on invalid strings and kill(0) kills (potentially) a lot of processes.

ykonstant
0 replies
11h51m

I can't help sharing one of the loveliest uses of `kill 0` I know:

    #!/bin/sh
    #
    #    Usage: upto LIMIT COMMAND
    #        Run COMMAND until LIMIT seconds have passed, then exit.
    #
    test "$1" -gt 0 || {
     printf '%s\n' " Error: first argument must be a positive integer."
     exit 1
    }
    
    sh -ic '
     sleeptime=$1
     shift
     exec 3>&1 2>&3
     { 
      "$@" >&3
      kill 0
     } |
     {
      sleep "${sleeptime}"
      kill 0
     }
    ' sh "$@"

o11c
0 replies
14h40m

There's a third use of PID 0, besides the already-mentioned "idle" and "self".

On Linux, `getppid` returns 0 if the parent is a process in another PID namespace.

kalleboo
0 replies
5h44m

On Darwin/macOS it's easy - kernel_task shows up with PID 0 right there in top!

eloh
0 replies
2h53m

Isn't it lovely how all these detailed code references are just a link away via GitHub?

blueflow
0 replies
14h17m

Hah. Another topic where the "common knowledge" is just utter garbage and actual research yields a different picture. That doesn't stop people from being convinced of it.

The author of this post did the only correct thing and checked the kernel's source code, with is the authoritative source for this information.

The conclusions at the end are a bit whacky.

bhasi
0 replies
17h52m

This is very interesting. For those interested in following all the parts of early kernel booting that were out of scope for this article, please read this fantastic resource: https://0xax.gitbooks.io/linux-insides/content/

Taniwha
0 replies
6h25m

It's interesting that the v4 code linked reuses pid 0 (the code that assigns pids simply does "p->p_pid = ++mpid;") - I vaguely remember having to fix that in kernels we were working on in the mid 80s