Threads vs. Processes: They’re not the same thing!
Linux, Programming August 4th, 2007 - 8,139 views
I read a lot of tech-related blogs and other tech-news, and I’ve caught a number of very talented programmers and intelligent technologists using the terms thread and process interchangibly. Forgive me for being pedantic, but they’re not the same thing! It’s true that threads and processes are very similar: they’re both methods of parallelizing an application. But the similarities pretty much stop there.
A process is usually defined as an instance of a program that is being executed, including all variables and other information describing the program’s state. Processes have a life cycle: they are spawned, optionally generate one or more child processes, and eventually die. Each process is an independent entity to which system resources (CPU time, memory, etc.) are allocated. And each processes is executed in a separate address space. Thus, one process cannot access variables or other data structures that are defined in another process. If two processes want to communicate, they have to use inter-process communication mechanisms like files, pipes, or sockets.
The term thread is short for a thread of execution, and refers to a particular execution path through a process. Threads and processes work differently on different operating systems but, in general, multiple threads can share the state information of a single process. Since threads share memory and other system resources, they can communicate directly via variables and other memory structures. And because threads can share a single address space, context switching between threads is faster than switching between processes.
Many modern applications take advantage of multithreading. In particular, applications that perform a lot of I/O — like web servers and databases — can drastically improve performance by implementing a multithreaded execution model. On a multiprocessor system, multiple threads of execution can even run simultaneously within a single process. Unfortunately, the threading abstractions in modern operating systems can be hard to understand, and are unavailable in certain programming languages.
So, one more time. A process can be thought of as a thread, plus an address space, file descriptors, and a bunch of other data. A single process can consist of multiple threads, and when one thread modifies a process resource, the change is immediately visible to sibling threads. On the other hand, processes have their own address spaces, and are unable to communicate directly. Processes and threads are not the same thing.

August 4th, 2007 at 9:05 pm
There you go, correcting people again. But this is an important distinction both in terms of capabilities and performance.
mike Says:August 4th, 2007 at 9:23 pm
Haha. I didn’t identify anyone in particular, just saying…
It does make a pretty huge difference though. The reason lighttpd is so much faster than Apache is mostly due to lighttpd’s threading / non-blocking I/O architecture vs. Apache’s forking (there’s a threaded version of Apache too, but it doesn’t work with PHP).
David Ulevitch Says:August 4th, 2007 at 10:59 pm
Very nice article. Converting a single-threaded program into a process with multiple threads is often non-trivial. When starting from scratch, it can be nice, but code can get hairy when trying to handle multiple threads on an existing single-threaded code-base.
When in that situation, operationally, I’ve always just tried to find ways to multiplex the execution of the program. Specifically, for single-threaded web apps I’ve found FastCGI to save the day a number of times rather than rewriting the code. :-)
Blake Brannon Says:August 5th, 2007 at 9:09 am
Thanks for the clarification. Like most words in the english language, (i.e. ethical and moral) people have lost the distinction between the two meanings and begun to interchange them in dialog. Good job keeping us mortals straight.
Markus Says:August 6th, 2007 at 1:53 am
kinda guessing this was generated by my last coment ;)
i wasn’t saying threads and processes are the same thing, only that in the linux kernel, there “is no concept of a thread. Linux implements threads as standard processes. The Linux kernel does not provide any special scheduling semantics or data structures to represent threads. Instead, a thread is merely a process that shares certain resources with other processes.” [1]
[1] Love, Robert: “Linux Kernel Development Second Edition”, Novell Press, 2005
mike Says:August 6th, 2007 at 12:17 pm
Markus, I was thinking of writing this post a while ago, but you certainly reminded me =p. You’re right though, the Linux kernel accounts for / schedules threads and processes the same way — the same data structures are used to manage/schedule threads and processes.
Benson Says:February 12th, 2008 at 4:07 pm
hey tere
I am new to the subject of thread and process. Can someone tell me why is the average time that creats a thread is faster than creating a process?
Best regard