Linux:进程概念的引入和理解

文章目录

  • 进程的初步理解
  • 进程的实质理解
  • 查看进程

前面对操作系统有了一个基础的认知,从中得出的最重要的一个思想是,在认识一个新事物前要先描述,再组织,有了这样的思想也可以用于学习进程的概念

进程的初步理解

有了前面的思想,那么如何来描述一个进程?进程的概念是什么呢?
在官方的解释中,将进程解释为运行起来的程序和在内存中的程序,严格意义来说这并不好理解,进程和程序很明显是不一样的,但是仅仅通过这样的概念是无法达到理解进程的程度,因此就需要进行其他方面的理解

当程序在运行的时候,是从哪里开始的?这要由程序的存储位置决定,程序终究本质上是一个文件,既然是文件就必然是存储在了磁盘中,因此程序要运行起来就要从磁盘转移到内存,这个转移的过程就叫做加载,那么程序现在已经加载到内存中了,但是内存中只是一个一个单独的程序,如何将它们进行管理?因此就出现了前面提到的关键词—操作系统

操作系统是一个纯粹的管理类的软件,同时也是在电脑运行的时候第一个启动的软件,因此不管什么时候将磁盘中的文件加载到内存中,此时内存中早已有一个软件被提前启动了,这个软件就是操作系统,那么操作系统就有了一个作用:用来管理这些磁盘中的程序,当它们进来的时候已经是进程了,那操作系统是不是要管理这些进程?那如何管理?就要先描述再组织

如何描述进程?

在日常生活中,想要管理人,就要先对人进行描述,比如定义一个结构体,里面存储的是人的各种属性,比如说学号,姓名,住址,手机号等等…有了这些信息就能把人的数据进行管理,能管理人的数据就能对人进行组织进行具体的实质性的管理

那么对于进程来说也是这样,那如何描述进程?有很多描述的属性,比如说进程的id,进程的代码地址,进程的数据地址,进程的状态,进程的优先级,进程的链接字段,能不能把进程像链表一样链接起来可以帮助我们快速的找到进程?因此肯定会有指针的概念存在,前面说的这些属性就共同组成了进程的概念,那这个结构体的名字叫什么?它有一个官方的名字叫做进程的pcb,而通过这些进程的pcb,操作系统就可以像人管理人一样将进程也进行管理,这样就将操作系统和进程结合在了一起

进程的实质理解

那前面铺垫了很多,将进程和操作系统联系在了一起,那么说到头,进程到底是什么呢?

进程=可执行程序+内核数据结构(PCB)

由于我们的研究对象都是在Linux环境下进行研究,那么重点是讲述在Linux下的进程概念,在Linux操作系统下,进程的PCB被叫做是task_struct,也就是说,在Linux下描述进程的结构体不叫PCB,叫做task_struct,这是Linux内核中的一种数据结构,它会被装载到内存中,并且当中会包含着进程的信息,用下图来简答说明这段概念

在这里插入图片描述
图片很清晰的表现了上面内容的具体意义,磁盘上的可执行程序被加载到了内存中,而内存中早已加载好了操作系统等待着管理进程,当程序进入内存后,操作系统就为每一个进程创建了独属于它的task_struct,这个结构体是用来描述这个进程的,当进来的每一个进程都有一个独属于它的结构体后,就可以利用这些结构体的数据对进程进行管理,在内部操作系统通常是使用链表的形式对进程进行管理,当有进程被杀死后就删除,有新的进程进来就插入,采用的是双向链表能够提高一些效率等等,因此上面对于进程的概念就很好理解了,进程就是可执行程序和内核的数据结构

下面对进程的理解进行一些其他的解析:

进程的管理被建模成了数据结构

数据结构是被抽象出来的概念,那么在实际应用中其实数据结构存在的意义就在于此处,通过数据结构可以很方便的对于数据的管理,以上图展示的进程为例,操作系统作为管理类的软件要进行数据的管理,那管理数据的方式就是借助数据结构,借助双向链表的这种数据结构,就可以把对于进程的管理建模成为对于双向链表的增删查改,有了这样的思维管理和处理数据就显得简单了许多

进程的PCB可以存在于多个链表

进程的PCB不一定一定是上图中画的这一条链表,从本质上来说链表中的这些节点只是链表中的一些数据而已,可以在很多条链表中同时存在这些数据

进程不一定只能在链表中

上面提到了,数据结构可以用来管理数据,对于上图的描述来说,只是讲数据放在了链表中进行管理,但是实际上并不意味着只能在链表中进行数据的管理,还可以放在队列等其他数据结构中进行建模管理

小结

从这一个章节结束后,对于进程的理解就已经初步搭建起来了,但这都是理论上的停留,对于进程的实践可以更好的帮助理解进程

查看进程

Linux中,如果想要查看进程,可以在/proc系统文件夹中查看

在这里插入图片描述
可以使用ps和top来获取进程信息

# 查看进程的信息
[test@VM-16-11-centos ~]$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1 191148  3812 ?        Ss   Jul15  11:50 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root         2  0.0  0.0      0     0 ?        S    Jul15   0:02 [kthreadd]
root         4  0.0  0.0      0     0 ?        S<   Jul15   0:00 [kworker/0:0H]
root         6  0.0  0.0      0     0 ?        S    Jul15   2:03 [ksoftirqd/0]
root         7  0.0  0.0      0     0 ?        S    Jul15   0:26 [migration/0]
root         8  0.0  0.0      0     0 ?        S    Jul15   0:00 [rcu_bh]
root         9  0.0  0.0      0     0 ?        S    Jul15  21:54 [rcu_sched]
root        10  0.0  0.0      0     0 ?        S<   Jul15   0:00 [lru-add-drain]
root        11  0.0  0.0      0     0 ?        S    Jul15   0:14 [watchdog/0]
root        12  0.0  0.0      0     0 ?        S    Jul15   0:12 [watchdog/1]
root        13  0.0  0.0      0     0 ?        S    Jul15   0:27 [migration/1]
root        14  0.0  0.0      0     0 ?        S    Jul15   1:51 [ksoftirqd/1]
root        16  0.0  0.0      0     0 ?        S<   Jul15   0:00 [kworker/1:0H]
root        18  0.0  0.0      0     0 ?        S    Jul15   0:00 [kdevtmpfs]
root        19  0.0  0.0      0     0 ?        S<   Jul15   0:00 [netns]
root        20  0.0  0.0      0     0 ?        S    Jul15   0:01 [khungtaskd]
root        21  0.0  0.0      0     0 ?        S<   Jul15   0:00 [writeback]
root        22  0.0  0.0      0     0 ?        S<   Jul15   0:00 [kintegrityd]
root        23  0.0  0.0      0     0 ?        S<   Jul15   0:00 [bioset]
root        24  0.0  0.0      0     0 ?        S<   Jul15   0:00 [bioset]
root        25  0.0  0.0      0     0 ?        S<   Jul15   0:00 [bioset]
root        26  0.0  0.0      0     0 ?        S<   Jul15   0:00 [kblockd]
root        27  0.0  0.0      0     0 ?        S<   Jul15   0:00 [md]
root        28  0.0  0.0      0     0 ?        S<   Jul15   0:00 [edac-poller]
root        29  0.0  0.0      0     0 ?        S<   Jul15   0:00 [watchdogd]
root        35  0.0  0.0      0     0 ?        S    Jul15   0:02 [kswapd0]
root        36  0.0  0.0      0     0 ?        SN   Jul15   0:00 [ksmd]
root        37  0.0  0.0      0     0 ?        SN   Jul15   0:07 [khugepaged]
root        38  0.0  0.0      0     0 ?        S<   Jul15   0:00 [crypto]
root        46  0.0  0.0      0     0 ?        S<   Jul15   0:00 [kthrotld]
root        48  0.0  0.0      0     0 ?        S<   Jul15   0:00 [kmpath_rdacd]
root        49  0.0  0.0      0     0 ?        S<   Jul15   0:00 [kaluad]
root        51  0.0  0.0      0     0 ?        S<   Jul15   0:00 [kpsmoused]
root        52  0.0  0.0      0     0 ?        S<   Jul15   0:00 [ipv6_addrconf]
root        65  0.0  0.0      0     0 ?        S<   Jul15   0:00 [deferwq]
root       106  0.0  0.0      0     0 ?        S    Jul15   1:42 [kauditd]
root       203  0.0  0.0      0     0 ?        S<   Jul15   0:00 [iscsi_eh]
root       253  0.0  0.0      0     0 ?        S<   Jul15   0:00 [ata_sff]
root       262  0.0  0.0      0     0 ?        S    Jul15   0:00 [scsi_eh_0]
root       267  0.0  0.0      0     0 ?        S<   Jul15   0:00 [scsi_tmf_0]
root       268  0.0  0.0      0     0 ?        S    Jul15   0:00 [scsi_eh_1]
root       269  0.0  0.0      0     0 ?        S<   Jul15   0:00 [scsi_tmf_1]
root       272  0.0  0.0      0     0 ?        S<   Jul15   0:00 [ttm_swap]
root       277  0.0  0.0      0     0 ?        S<   Jul15   0:31 [kworker/0:1H]
root       292  0.0  0.0      0     0 ?        S    Jul15  11:01 [jbd2/vda1-8]
root       293  0.0  0.0      0     0 ?        S<   Jul15   0:00 [ext4-rsv-conver]
root       300  0.0  0.0      0     0 ?        S<   Jul15   0:20 [kworker/1:1H]
root       381  0.0  3.0 134284 62172 ?        Ss   Jul15  15:18 /usr/lib/systemd/systemd-journald
root       404  0.0  0.0 116644  1088 ?        Ss   Jul15   0:00 /usr/sbin/lvmetad -f
root       409  0.0  0.0  45388  1744 ?        Ss   Jul15   0:00 /usr/lib/systemd/systemd-udevd
root       501  0.0  0.0      0     0 ?        S<   Jul15   0:00 [nfit]
root       515  0.0  0.0  55532  1064 ?        S<sl Jul15   3:11 /sbin/auditd
libstor+   556  0.0  0.0   8580   796 ?        Ss   Jul15   0:13 /usr/bin/lsmd -d
dbus       561  0.0  0.1  60312  2308 ?        Ss   Jul15  10:41 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --sys
root       566  0.0  0.0   4388   520 ?        Ss   Jul15   0:00 /usr/sbin/acpid
root       567  0.0  0.0  26384  1688 ?        Ss   Jul15   4:47 /usr/lib/systemd/systemd-logind
polkitd    568  0.0  0.4 614324  9852 ?        Ssl  Jul15   3:20 /usr/lib/polkit-1/polkitd --no-debug
root       612  0.0  0.0      0     0 ?        S<   Jul15   0:00 [ib-comp-wq]
root       613  0.0  0.0      0     0 ?        S<   Jul15   0:00 [kworker/u5:0]
root       614  0.0  0.0      0     0 ?        S<   Jul15   0:00 [ib-comp-unb-wq]
root       615  0.0  0.0      0     0 ?        S<   Jul15   0:00 [ib_mcast]
root       616  0.0  0.0      0     0 ?        S<   Jul15   0:00 [ib_nl_sa_wq]
root       621  0.0  0.0      0     0 ?        S<   Jul15   0:00 [mlx5_ib_sigerr_]
root      1005  0.0  0.1 103004  2200 ?        Ss   Jul15   0:00 /sbin/dhclient -q -lf /var/lib/dhclient/dhclient--eth0.lease -pf /var/run/d
root      1070  0.0  0.4  61488 10140 ?        S<Ls Jul15   0:00 /sbin/iscsid -f
root      1072  0.0  0.7 574288 16108 ?        Ssl  Jul15   7:35 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
root      1075  0.0  0.0  50096   956 ?        Ssl  Jul15   0:00 /usr/sbin/rshim
root      1180  0.0  1.5 731540 31080 ?        Ssl  Jul15   8:42 /usr/sbin/rsyslogd -n
root      1188  0.0  0.0  25908   952 ?        Ss   Jul15   0:00 /usr/sbin/atd -f
root      1195  0.0  0.0 126424  1656 ?        Ss   Jul15   0:42 /usr/sbin/crond -n
root      1205  0.0  0.0 110208   832 ttyS0    Ss+  Jul15   0:00 /sbin/agetty --keep-baud 115200,38400,9600 ttyS0 vt220
root      1206  0.0  0.0 110208   820 tty1     Ss+  Jul15   0:00 /sbin/agetty --noclear tty1 linux
root      1318  0.0  0.1  91888  2220 ?        Ss   Jul15   0:16 /usr/libexec/postfix/master -w
postfix   1328  0.0  0.1  92168  4052 ?        S    Jul15   0:03 qmgr -l -t unix -u
root      1370  0.0  0.2 113000  4368 ?        Ss   Jul15   3:15 /usr/sbin/sshd -D
root      1565  0.0  0.0  97492  1708 ?        Sl   Jul15   0:45 /usr/local/qcloud/stargate/bin/sgagent -d
ntp       1800  0.0  0.1  32044  2076 ?        Ss   Jul15   0:07 /usr/sbin/ntpd -u ntp:ntp -g
root      3243  0.0  0.0      0     0 ?        S    Sep21   0:00 [kworker/u4:0]
root      4695  0.0  0.0      0     0 ?        S    14:26   0:00 [kworker/1:0]
root      5449  0.0  0.8 988576 17532 ?        Sl   Jul15  26:46 /usr/local/qcloud/YunJing/YDLive/YDLive
root     14438  0.0  0.0      0     0 ?        S    Sep19   0:01 [kworker/u4:2]
root     14808  0.8  2.5 989324 52008 ?        Sl   Sep11 135:03 /usr/local/qcloud/YunJing/YDEyes/YDService
root     14911  0.0  0.3 1026504 7044 ?        Sl   Sep11   3:00 /bin/sh -c sleep 100
root     15264  0.0  0.3  29668  6356 ?        Sl   Aug30   4:58 /usr/local/qcloud/tat_agent/tat_agent
root     20043  0.0  0.3 157820  7604 ?        S    Aug31   0:21 barad_agent
root     20051  0.0  0.4 165176  9496 ?        S    Aug31  22:03 barad_agent
root     20052  0.6  0.8 756260 16492 ?        Sl   Aug31 202:31 barad_agent
test     20530  0.0  0.0  22244  1360 ?        Ssl  Sep12   0:00 /home/test/.VimForCpp/nvim test.s
test     20543  0.0  0.2  20904  4192 ?        Ssl  Sep12   0:00 /home/test/.VimForCpp/vim/bundle/LanguageClient-neovim/bin/languageclient
postfix  20942  0.0  0.2  91992  4108 ?        S    15:34   0:00 pickup -l -t unix -u
root     24271  0.0  0.0      0     0 ?        S    15:48   0:00 [kworker/0:0]
root     27220  0.0  0.0      0     0 ?        S    16:00   0:00 [kworker/1:1]
root     27911  0.0  0.0      0     0 ?        R    16:03   0:00 [kworker/0:2]
root     29238  0.0  0.2 156876  5400 ?        Ss   16:08   0:00 sshd: test [priv]
test     29240  0.0  0.1 156876  2360 ?        D    16:08   0:00 sshd: test@pts/0
test     29241  0.0  0.1 116992  3468 pts/0    Ss   16:08   0:00 -bash
root     29450  0.0  0.0      0     0 ?        S    16:09   0:00 [kworker/0:1]
root     29765  0.0  0.0      0     0 ?        S    16:10   0:00 [kworker/1:2]
test     30118  0.0  0.0 155452  1872 pts/0    R+   16:11   0:00 ps aux

下面用实验证明进程的存在

首先创建test.c文件

#include <stdio.h>
#include <unistd.h>int main()
{while(1){printf("正在打印进程\n");sleep(1);}return 0;
}

创建Makefile文件

cc=gcc
src=test.c
target=mybin$(target):$(src)gcc $^ -o $@
.PHONY:clean
clean:rm -f $(target)

此时启动程序,启动的同时观察进程的变化情况

# 启动程序
[test@VM-16-11-centos test]$ ./mybin
# 观察进程中mybin的情况
[test@VM-16-11-centos test]$ ps aux |grep mybin
test     16029  0.0  0.0   4216   352 pts/0    S+   17:24   0:00 ./mybin
test     16056  0.0  0.0 112816   980 pts/1    S+   17:24   0:00 grep --color=auto mybin

从中看出,mybin进程是确实存在的,并且其中还包含一个grep --color=auto mybin进程,因为调用grep管道指令也算一个进程

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/142524.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

学习路之PHP--lumen安装配置

一、下载lumen源码 composer create-project --prefer-dist laravel/lumen blog 安装lumen-generator composer require flipbox/lumen-generator 二、配置 bootstrap\app.php 97行 $app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);三、生成…

VS CODE中的筛选器如何打开?

最近更新了vscode1.82版本&#xff0c;发现在git管理界面有一个“筛选器”功能&#xff0c;十分好用&#xff0c;后来关掉了&#xff0c;找了好久都没有找到办法打开这个筛选器功能&#xff0c;今天无意中不知道按到了哪个快捷键&#xff0c;打开了&#xff0c;就是下图这个&am…

buuctf-[网鼎杯 2020 朱雀组]phpweb

1.打开网站&#xff0c;吓我一跳 2.查看源代码&#xff0c;主要看到timezone&#xff0c;然后这个页面是五秒就会刷新一次 一开始去搜了这个&#xff0c;但是没什么用 3.使用bp抓包 会发现有两个参数&#xff0c;应该是用func来执行p 4.修改func和p file_get_contents&#…

全新UI基于Thinkphp的最新自助打印系统/云打印小程序源码/附教程

这是一款全新的基于Thinkphp的最新自助打印系统&#xff0c;最新UI界面设计的云打印小程序源码&#xff0c;带有简单的教程。 下载地址&#xff1a;https://bbs.csdn.net/topics/617324130

3分钟,免费制作一个炫酷实用的数据可视化大屏!

在当前大数据时代背景下&#xff0c;数据已成为在工业革命中如同煤炭、石油一般宝贵的资源。但是由于数据越来越庞大、越来越复杂&#xff0c;导致数据的可读性也越来越低。因此&#xff0c;对数据可视化的需求也越来越高&#xff0c;需要解决的问题也越来越复杂&#xff0c;而…

进程的内存映像

组成部分 代码段&#xff1a;即程序的二进制代码&#xff0c;只读&#xff0c;可被多个进程共享数据段&#xff1a;包括全局变量和静态变量进程控制块PCB&#xff1a;在系统区&#xff08;内核区&#xff09;&#xff0c;操作系统通过PCB来控制和管理进程堆&#xff1a;用来存放…

Docker部署ActiveMQ消息中间件

1、准备工作 docker pull webcenter/activemq:5.14.3 Pwd"/data/software/activemq" mkdir ${Pwd}/data -p2、运行容器 docker run -d --name activemq \-p 61616:61616 \-p 8161:8161 \-v ${Pwd}/data:/opt/activemq/data \-v /etc/localtime:/etc/localtime \--r…

4+机器学习+实验验证

今天给同学们分享一篇4机器学习实验验证的生信文章“Identification and Analysis of Neutrophil Extracellular Trap-Related Genes in Osteoarthritis by Bioinformatics and Experimental Verification”&#xff0c;这篇文章于2023年8月31日发表在 J Inflamm Res 期刊上&am…

HTMl案例二:注册页面

<!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>综合案例-注册页面</title> </head><…

网络编程

一、什么是网络编程 二、基本的通信架构 三、网络通信的三要素 1.IP地址 1.IPv4&#xff0c;IPv6 2.IP域名 3.公网IP &#xff0c;内网IP&#xff0c;本机IP 4.InetAddress import java.net.InetAddress;public class InetAddressTest {public static void main(String[] args)…

Hadoop、Spark、Storm、Flink区别及选择

hadoop、spark、storm、flink如何选择 hadoop和spark是更偏向于对大量离线数据进行批量计算&#xff0c;提高计算速度storm和flink适用于实时在线数据&#xff0c;即针对源源不断产生的数据进行实时处理。至于storm和flink之间的区别在于flink的实时性和吞吐量等要比storm高。…

Java中的泛型

一. 泛型简介 泛型&#xff0c;即“参数化类型”。 作为Java中常用且重要的一个概念&#xff0c;泛型帮我们实现了代码重用&#xff0c;也保证了类型安全。但关于它的详细内容&#xff0c;目前很多同学还不清楚&#xff0c;所以接下来就带各位来学习这个重要的知识点。 背景 …

利用fiddler正向代理前端请求到本地后端

前景&#xff1a;在实际开发测试环境中&#xff0c;&#xff08;前后端均已上线到测试服务器或前端以上线而后端还在开发中)。在测试过程中&#xff08;前端页面点击&#xff0c;功能测试&#xff09;发现了bug或异常点。 正常排查问题可能是先利用浏览器检查工具查看接口的返回…

flv怎么转换成mp4格式?准备3个方法给大家

flv怎么转换成mp4格式&#xff1f;FLV是一种流行的视频文件格式&#xff0c;最初由Adobe公司开发&#xff0c;用于在Web上播放和传输视频内容。FLV格式以其较小的文件大小和较高的压缩比而闻名&#xff0c;并广泛应用于在线视频分享平台、流媒体服务和网络广告等领域。能够提供…

驱动开发---基于gpio子系统编写LED灯的驱动

一、GPIO子系统相关API 1.解析GPIO相关的设备树节点 struct device_node *of_find_node_by_path(const char *path) 功能&#xff1a;根据设备树节点路径解析设备树节点信息 参数&#xff1a; path&#xff1a;设备树所在的节点路径 /mynode0X12345678 返回值&#xff1a;成…

JS的基本组成

JavaScript的实现包括以下3个部分&#xff1a; 模块功能ECMAScript(核心)描述了JS的语法和基本对象。文档对象模型 &#xff08;DOM&#xff09;处理网页内容的方法和接口浏览器对象模型&#xff08;BOM&#xff09;与浏览器交互的方法和接口 javascript 有三部分构成&#…

腾讯mini项目-【指标监控服务重构-会议记录】2023-07-26

2023-07-26组长会议纪要 A组 项目对齐和问题 分配需求&#xff0c;SLI指标上报&#xff0c;暂时没有实际效果 每个人负责一条指标&#xff0c;同步代码&#xff0c;时间问题还是难题跟B组同学请教&#xff0c;答疑 问题&#xff1a;启动 Tracer 【已解决】 环境问题&#xf…

Python读取Excel每一行为列表—大PK(openpyxl\pandas\xlwings\xlrd)看谁用时少?

目录 背景使用—openpyxl&#xff08;耗时89秒输出&#xff09;使用—pandas&#xff08;耗时44秒输出&#xff09;使用—xlwings&#xff08;耗时15秒输出&#xff09;使用—xlrd&#xff08;耗时47秒输出&#xff09;总结 背景 我们在平常办公的时候&#xff0c;尤其是财务人…

asisctf 2023 web hello wp

hello 开题&#xff0c;直接给了源码。 <?php /* Read /next.txt Hint for beginners: read curls manpage. */ highlight_file(__FILE__); $url file:///hi.txt; if(array_key_exists(x, $_GET) &&!str_contains(strtolower($_GET[x]),file) && !str_c…

ElementUI之动态树+数据表格+分页

目录 前言 一.ElementUI之动态树 1.前端模板演示 2.数据绑定 2.1 通过链接获取后台数据 2.2 对链接进行绑定 2.3添加动态路由 2.4 配置路由 3.效果演示 二.数据表格动态分页 1.前端模板 2.通过JS交互获取后端数据 3 效果演示 前言 Element UI 是一个基于 Vue.js 的开…