Processes vs Threads
A process is an executing instance of an application. What does that mean? Well, for example, when you double-click the Microsoft Word icon, you start a process that runs Word. A thread is a path of execution within a process. Also, a process can contain multiple threads. When you start Word, the operating system creates a process and begins executing the primary thread of that process.
It’s important to note that a thread can do anything a process can do. But since a process can consist of multiple threads, a thread could be considered a ‘lightweight’ process. Thus, the essential difference between a thread and a process is the work that each one is used to accomplish. Threads are used for small tasks, whereas processes are used for more ‘heavyweight’ tasks – basically the execution of applications.
Another difference between a thread and a process is that threads within the same process share the same address space, whereas different processes do not. This allows threads to read from and write to the same data structures and variables, and also facilitates communication between threads. Communication between processes – also known as IPC, or inter-process communication – is quite difficult and resource-intensive.
MultiThreading
Threads, of course, allow for multi-threading. A common example of the advantage of multithreading is the fact that you can have a word processor that prints a document using a background thread, but at the same time another thread is running that accepts user input, so that you can type up a new document.
If we were dealing with an application that uses only one thread, then the application would only be able to do one thing at a time – so printing and responding to user input at the same time would not be possible in a single threaded application.
Each process has it’s own address space, but the threads within the same process share that address space. Threads also share any other resources within that process. This means that it’s very easy to share data amongst threads, but it’s also easy for the threads to step on each other, which can lead to bad things.
Subscribe to our newsletter for more free interview questions.
Multithreaded programs must be carefully programmed to prevent those bad things from happening. Sections of code that modify data structures shared by multiple threads are called critical sections. When a critical section is running in one thread it’s extremely important that no other thread be allowed into that critical section. This is called synchronization, which we wont get into any further over here. But, the point is that multithreading requires careful programming.
Also, context switching between threads is generally less expensive than in processes. And finally, the overhead (the cost of communication) between threads is very low relative to processes.
Here’s a summary of the differences between threads and processes:
1. Threads are easier to create than processes since they |
Processes vs Threads的更多相关文章
- Google Android官方文档进程与线程(Processes and Threads)翻译
android的多线程在开发中已经有使用过了,想再系统地学习一下,找到了android的官方文档,介绍进程与线程的介绍,试着翻译一下. 原文地址:http://developer.android.co ...
- Processes and Threads
http://www.cnblogs.com/xitang/archive/2011/09/24/2189460.html Processes and Threads 译者署名: 呆呆大虾 译者微博: ...
- /usr/bin/uwsgi --http :8888 --wsgi-file wsgi.py --master --processes 4 --threads 2
/usr/bin/uwsgi --http :8888 --wsgi-file wsgi.py --master --processes 4 --threads 2 root 18756 0.0 0. ...
- Android Processes and Threads
Processes and Threads When an application component starts and the application does not have any oth ...
- Windbg Processes and Threads(进程和线程)窗口的使用
在 WinDbg 中,进程和线程窗口中显示有关系统. 进程和线程正在调试的信息. 此窗口还可选择新的系统. 进程和线程处于活动状态. 如何打开进程和线程窗口 通过菜单View--->Proces ...
- Processes and Threads (转)
http://www.cnblogs.com/xitang/archive/2011/09/24/2189460.html 原文 http://developer.android.com/guide/ ...
- [原]Threads vs Processes in Linux 分析
Linux中thread (light-weighted process) 跟process在實作上幾乎一樣. 最大的差異來自於,thread 會分享 virtual memory address s ...
- 《深入理解Linux内核》阅读笔记 --- Chapter 3 Processes
Process Switching 1.The set of data that must be loaded into the registers before the process resume ...
- Android 性能优化(16)线程优化:Creating a Manager for Multiple Threads 如何创建一个线程池管理类
Creating a Manager for Multiple Threads 1.You should also read Processes and Threads The previous le ...
随机推荐
- TYVJ P1091 等差数列 Label:dp
背景 广东汕头聿怀初中 Train#3 Problem 3 描述 等差数列的定义是一个数列S,它满足了(S[i]-S[i-1]) = d (i>1).显然的一个单独的数字或者两个数字也可以形成一 ...
- 【BZOJ】1085: [SCOI2005]骑士精神(A*启发式搜索)
http://www.lydsy.com/JudgeOnline/problem.php?id=1085 囧啊囧,看了题解后写了个程序,但是样例总过不了T+T,调试了不下于1个小时,肉眼对拍看了根本看 ...
- Bestcoder Round# 80
[1003 Sequence] 指数循环节,注意a mod p = 0的情况.此时你的循环节如果返回0,这时你会输出1,而实际上应该是0 #include <algorithm> #inc ...
- hdu Collect More Jewels
思路: 先用bfs求出入口,宝物,出口,两两之间的最短距离. 在用dfs搜索所有情况,求出从入口走到出口能获得的最大价值. 我们要解决几个问题:1.求入口到第一个取宝物的地方的最短距离 2.求第i个取 ...
- 移动web app开发小贴士 收藏有用
1 创建主屏幕图标 (Creating a home screen icon ,for ios) 1 2 3 4 5 6 //57*57 <link rel="apple-touc ...
- Wps 方框里面加勾
1.选择插入-->选择符号 2.选择更多 3.选择 字体Wingdings 然后下拉到最后.就看到了
- cms 二级域名修改信息
\CMS\Collect\PageRes.cs _content = _content.Replace(r.orgurl, newurl); _content = _content.Replace(r ...
- 使用Hydra扫描网络中存在SSH弱登录密码的Linux系统
1. apt-get install cmake libssl-dev 2. apt-get install hydra (需要图形界面的话用hydra-gtk) 3. hydra -s 22 -v ...
- shopnc2014年11版数据库字典
shopnc_activity 表注释: 活动表 字段 类型 空 默认 注释 activity_id mediumint(9) 否 id activity_title varchar(255) 否 ...
- Oracle11g创建表空间语句
在plsql工具中执行以下语句,可建立Oracle表空间. /*分为四步 *//*第1步:创建临时表空间 */create temporary tablespace yuhang_temp temp ...