I notice that chrome (famously now), creates loads of instances in task manager. Is that lots of threads and one process? Or is it multiple processes. i.e. is task manager showing threads, or is it showing processes?
Suppose I go to the orb/start, and I launch cmd, then I go there again and launch another cmd. Is that two separate processes, rather than one process with two threads?
Now suppose I launch a cmd, then from there, I launch another cmd. Is that one process two threads? Or is that two processes?
Answer
The Windows "Task Manager" only shows processes. (Otherwise you would see a lot of duplicates for everything, since almost all Windows apps are multi-threaded, including Chrome.) To see threads of a process, use Process Explorer or Process Hacker; both of them have a "Threads" tab in the process properties dialog.
When you run something via Run… or Command Prompt, it always starts as a new process. It doesn't make any sense for it to be a new thread in an existing process, since threads share memory and other resources, so a new thread created "from nowhere" just wouldn't know what to do with what it got; it'd trample all over the running app.
That said, once the new process starts, it can contact an existing instance. That's what both Chrome and Firefox do – they just send a "hey, the user wants a new window" IPC message to the 'master' Firefox process, and exit immediately afterwards.
As for that new window, usually it doesn't get a new thread on its own – most of the time, if a single process decides to open multiple windows, they all run on the same "UI thread", since only the main thread receives window messages. Instead, additional threads are used for background and/or long-running tasks.
As a side note, the Linux htop tool does show all threads by default (since Linux threads are no different from processes), and this confuses people every single time. If you use htop, make sure to select either "Show custom thread names" (as in the linked screenshot) or "Hide userland threads" (to get a traditional processes-only list).
For example, here's a small part of Linux Chromium's process tree, including both subprocesses and their threads (the main process didn't fit in the screenshot):
(Note that despite their green colouring, threads shown in htop are not green threads.)
No comments:
Post a Comment