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 ...
随机推荐
- 从Apache Storm学到的经验教训 —— storm的由来(转)
阅读目录 Storm来源 初探 再探 构建第一个版本 被Twitter收购 开源的Storm 发布之后 Storm的技术演进 构建开发者社区版 离开Twitter 提交到Apache Apache孵化 ...
- JavaScript 变量、函数与原型链
定义 || 赋值 1-函数的定义 函数定义的两种方式: “定义式”函数:function fn(){ alert("哟,哟!"); } “赋值式”函数:var fn = funct ...
- UOJ#77. A+B Problem
题目名称是吸引你点进来的. 从前有个 n 个方格排成一行,从左至右依此编号为 1,2,⋯,n. 有一天思考熊想给这 n 个方格染上黑白两色. 第 i 个方格上有 6 个属性:ai,bi,wi,li,r ...
- Linux_使用Linux之安装jdk 7
工具/原料 jdk7源码安装压缩包 方法/步骤 卸载OpenJDK rpm -qa | grep java rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1 ...
- Marching Cube
GPU-Marching-Cubes An Implementation of the Marching Cubes[1] Algorithm Marching Cubes Matlab The St ...
- openstack是什么
下面图片多来自互联网. 云计算: 云计算层次机构模型: IaaS 基础设施服务 PaaS 平台级服务 SaaS 软件级服务 官网:http://www.openstack.org/ openstack ...
- Leetcode | Work Break I & II
Work Break I Given a string s and a dictionary of words dict, determine if s can be segmented into a ...
- Ubuntu基础命令
显示历史命令的时间戳 echo 'HISTTIMEFORMAT="%F %T "' >> ~/.bashrc 解压文件/打包文件夹 tar -zxvf folder ...
- SecureCRT通过console口连接思科设备
- [IT学习]微软如何做网站内容治理
How Microsoft does SharePoint Governance for their internal platform english sources from:http://www ...