Process

program

program==code+data;
一个进程可以对应多个程序,一个程序也可以变成多个进程。程序可以作为一种软件资源长期保存,以文件的形式存放在硬盘

process:

  1. 相应的程序+CPU上下文+一组系统资源
  2. 动态性, 独立性, 并发性
  3. 一个CPU,任何时刻最多只能有一个进程去使用它

process VS thread

  • 进程的资源分配的基本单位,是分配资源的抽象:进程把一组相关资源组合起来,构成了一个资源平台,或者说资源环境,包括运行上下文,内存地址空间,打开的文件等
  • 线程是系统调度的基本单位,是执行流程的抽象:进程上的一条执行流程,就是线程
  • 早期不区分这两者,一个进程,既指它的资源平台,又指它的执行流程,后来把二者分开,所以进程=线程+资源平台
  • 在嵌入式系统中,不使用process或thread,而是使用task,具体这个task是什么得看情况,VxWorks,ucosII,Jbed里是thread; linux里是process

Linux Process Types

A process is an instance of a computer that is currently being executed. Associated with a process is a variety of attributes (ownership, nice value, and SELinux context , to name a few) that extend or limit its ability to access resources on the computer. In Linux, there are 3 types processes: User Process, Daemon Process, Kernel Process

User Process

A user process is one that is initiately by a regular user account and runs in user space. Unless it is run in a way that gives the process special permissions, an ordinary user process has no special access to the processor or to files on the system that don’t belong to the user who launched the process.

Daemon Process

A daemon process is an application that is designed to run in the background, typically managing some kind of ongoing service. They run in user space
System often start daemons at boot time and have them run continuously until the system is shut down. Daemon can also be started or stopped on demand, set to run at particular system run levels, and in some cases signaled to reload configuration information on the fly.
Although daemon processes are typically managed as services by the root user,daemon processes often run as non-root users by a user account that is dedicated to the services.

Kernel Process

A Kernel process executes only in kernel space. They are similar to daemon processes. The primary different is that kernel processes have full access to kernel data structures, which makes them more powerful than daemon processes, which run in user space. Kernel processes are not as flexible as daemon processes. You can change the behavior of a daemon process by changing configuration files and reloading the service, however, changing kernel processes may require recompiling the kernel.

Linux Process States

When a process is created, the system assigns it a state. The state field of the process descriptor describes the current state of the process. The value of the state field is usually set with a simple assignment:
8 primary states of a process in Linux:

  1. TASK_RUNNING(ready/waiting)
  2. TASK_RUNNING(running)
  3. TASK_INTERRUPTIBLE(interruptible sleep/blocked)
  4. TASK_UNINTERRUPTIBLE(uninterruptible sleep/blocked)
  5. TASK_STOPED(stoped)
  6. TASK_ZOMBIE(zombie)
  7. TASK_DEAD(dead)
  8. TASK_TRACED(traced)

3 additional states of a process in Linux:
Two additional states are available for processes in systems that support virtual memory. In both of these states, processes are "stored" on secondary memory (typically a hard disk)

  1. Swapped out and waiting (Also called suspended and waiting.)
    A process may be swapped out, that is, removed from main memory and placed on external storage by the scheduler. From here the process may be swapped back into the waiting state.
  2. Swapped out and (interruptible/uninterruptible)blocked (Also called suspended and blocked.)
    Processes that are blocked may also be swapped out. In this event the process is both swapped out and blocked, and may be swapped back in again under the same circumstances as a swapped out and waiting process.

Q: Stopped state VS Terminated state
A: Stopped means the process has received one of SIGSTOP / SIGTSTP / SIGTTIN / SIGTTOU, and won't do anything much until it receives a SIGCONT.
Zombie means the underlying program is no longer executing, but the process remains in the process table as a zombie process until its parent process calls the wait system call to read its exit status, at which point the process is removed from the process table, finally ending the process's lifetime. If the parent fails to call wait, this continues to consume the process table entry (concretely the process identifier or PID), and causes a resource leak.
Q: Interruptible Sleep State VS Uninterruptible Sleep state
A:Interruptible Sleep means the process is waiting wither for a particular time slot or a particular event to occur. Once one of those things occurs, the process will come out of Interruptible Sleep.
An Uninterruptible Sleep state is one that won’t handle a signal right away. It will wake only as a result of a waited-upon resource becoming available or after a time-out occurs duing that wait(if the time – out is specified when the process is put to sleep). It is mostly used by device drivers waiting for disk or network I/O. When the process is sleeping uninterruptibly, signals accumulated during the sleep are noticed when the process returns from system call or trap.

User Thread

  • Belongs to a user process
  • Managed by itself
  • Shares address space, open files, user credentials etc . in the same process
  • Privatize program counter, stack, and register context etc.
  • Unindependently scheduled
  • Extremely inexpensive, consume no kernel resource.
  • Useful to realize concurrence inside a user-process
  • pthread_create()

LWP

Light Weight Process--Kernel-supported user thread

  • Belongs to a user process
  • Managed by kernel
  • Shares address space, open files, user credentials etc . in the same process
  • In addition to program counter, stack, and register context etc. needs to maintain some user state
  • Independently scheduled
  • Expensive to block
  • Useful for independent tasks with little interaction with other lightweight processes
  • clone()

Kernel Thread

  • Need not be associated with a user process
  • Managed by kernel
  • Shares kernel text, global data etc.
  • Privatize program counter , kernel stack register context etc.
  • Independently scheduled
  • Inexpensive
    • Require space only for kernel stack and register context
    • Fast context switching as no memory mappings are to be flushed
  • Useful for operations such as asynchronous I/O
  • Request can be synchronously handled by the kernel thread
  • fork()/vfork()

Linux Process VS Thread VS LWP相关推荐

  1. linux下调试thread 类_linux下GDB调试

    linux下GDB是一个非常强大的调试工具,但是他不像vs一样具有强大的图形界面,基本都靠命令来进行调试,对于新手来说也算是个坎.下面就跟大家一起探究一下gdb这个强大的调试工具. 1.开启core ...

  2. Activity、Service、Task、Process和Thread的关系

    Activity, Service,Task, Process and Thread之间到底是什么关系呢? 我们可以把TASK看成一个应用程式本身,当使用者点击应用程式以后,就启动了TASK,而TAS ...

  3. Linux之线程Thread小结

    文章目录 线程相关操作函数 pthread_create 创建新新程 获取线程ID 线程终止 线程等待 分离线程 线程同步 互斥锁 条件变量 读写锁 信号量 线程私有数据 线程属性 属性操作函数 线程 ...

  4. The Linux Process Principle, PID、PGID、PPID、SID、TID、TTY

    转载自: https://blog.csdn.net/liujianfei526/article/details/50605813 2 Linux 进程的相关标识 0x1: PID(Process I ...

  5. Async Program 基本知识 (Process、Thread、Context Switch)

    处理序 (Process): 作为隔离应用程式的基本单位 例如:开启了一个程式,载入记忆体后,运行的instantce 就叫 Proces. 每一个 Process 占用 memory section ...

  6. Linux线程ID与内核LWP的关系

    先给出图,然后我将根据图来讲解二者的关系: 线程ID 在使用线程前,我们需要链接线程的pthread第三方库,在Linux中,第三方库被加载到PCB进程中的虚拟地址空间中的栈区与堆区之间的共享区. 我 ...

  7. Process and Thread

    关于进程及线程的基本含义及特性 1,"进程":process是操作系统中的基本执行单位.在多道程序设计的系统中往往同时有许多进程存在,它们要轮流占用处理器.这些交叉执行的并发进程相 ...

  8. Linux - Process

    查看具体进程的pid pidof [process name] eg: $pidof rpcbind 54965 查看Core文件的pattern cat /proc/sys/kernel/core_ ...

  9. linux下调试thread 类_在 RISC-V 芯片 GD32V 上运行 RT-Thread

    在 RISC-V 芯片 GD32V 上运行 RT-Thread GD32VF103 开发板 去年九月份的时候 RT-Thread 的 Andy Chen 组织定做了一块 GD32V 开发板,托 And ...

最新文章

  1. 【攻防世界008】answer_to_everything
  2. codeforces 516c// Drazil and Park// Codeforces Round #292(Div. 1)
  3. 信息安全完全参考手册之本书框架(目录)
  4. 【语义分割】评价指标代码函数:np.sum()、np.nansum()、np.nanmean()、np.diag()、np.bincount()
  5. 这五个有用的 CSS 属性完全被我忽视了
  6. zend studio和dreamweaver使用小笔记
  7. HTTP权威指南-概述
  8. qpython能使用json吗l_现在还能使用土墙吗?
  9. 【Power Query】使用Excel抓取淘宝天猫所有类目分类和cateId对应关系
  10. Win7 U盘安装Ubuntu16.04 双系统详细教程
  11. docker desktop 阿里云镜像加速
  12. MySQL数据库的主主同步配置
  13. 2022年全球智能盆栽行业分析报告
  14. 天翼云主攻“5G+云+AI”,新生态革命的冲锋
  15. 6、spss做logistic回归
  16. S2 优化数据库 第三章
  17. [论文阅读] BoT-SORT: Robust Associations Multi-Pedestrian Tracking
  18. epplus 速度_VSTO学习之路:学习使用Epplus(1)
  19. java 操作accdb_使用Java创建Access数据库文件(.mdb或.accdb)
  20. 前台Vue使用axios实现文件下载功能

热门文章

  1. Python3之socket编程(TCP/UDP,粘包问题,数据传输、文件上传)
  2. python 中的 del 使用方法
  3. P4570 [BJWC2011]元素(线性基+贪心)
  4. ntp服务器同步时间详细配置
  5. 说说说vue.js中的组
  6. Unity StartCoroutine 和 yield return 深入研究
  7. JCG新年献礼,JHR-N825R给力上市
  8. CentOS 5.5搭建Apache+PHP5.2x+MySQL5+Zend3(yum安装)
  9. [原创]vc中创建线程并传递参数
  10. 从1维到6维,一文读懂多维数据可视化策略