自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

帶你探索Linux上的/run

系統(tǒng) Linux
如果你沒(méi)有密切關(guān)注,你可能沒(méi)有注意到 Linux 系統(tǒng)在運(yùn)行時(shí)數(shù)據(jù)方面的工作方式有一些小但重大的變化。 雖然這種變化可能不足以讓你的襪子變濕,但它在 Linux 文件系統(tǒng)中提供了更多一致性,值得進(jìn)行一些探索。

[[268845]]

 Linux 系統(tǒng)在運(yùn)行時(shí)數(shù)據(jù)方面的工作方式發(fā)生了微小但重大的變化。

如果你沒(méi)有密切關(guān)注,你可能沒(méi)有注意到 Linux 系統(tǒng)在運(yùn)行時(shí)數(shù)據(jù)方面的工作方式有一些小但重大的變化。 它重新組織了文件系統(tǒng)中可訪問(wèn)的方式和位置,而這個(gè)變化在大約八年前就開(kāi)始了。雖然這種變化可能不足以讓你的襪子變濕,但它在 Linux 文件系統(tǒng)中提供了更多一致性,值得進(jìn)行一些探索。

要開(kāi)始,請(qǐng)轉(zhuǎn)到 /run。如果你使用 df 來(lái)檢查它,你會(huì)看到這樣的輸出:

  1. $ df -k .
  2. Filesystem 1K-blocks Used Available Use% Mounted on
  3. tmpfs 609984 2604 607380 1% /run

它被識(shí)別為 “tmpfs”(臨時(shí)文件系統(tǒng)),因此我們知道 /run 中的文件和目錄沒(méi)有存儲(chǔ)在磁盤(pán)上,而只存儲(chǔ)在內(nèi)存中。它們表示保存在內(nèi)存(或基于磁盤(pán)的交換空間)中的數(shù)據(jù),它看起來(lái)像是一個(gè)已掛載的文件系統(tǒng),這個(gè)可以使其更易于訪問(wèn)和管理。

/run 是各種各樣數(shù)據(jù)的家園。例如,如果你查看 /run/user,你會(huì)注意到一組帶有數(shù)字名稱的目錄。

  1. $ ls /run/user
  2. 1000 1002 121

使用長(zhǎng)文件列表可以發(fā)現(xiàn)這些數(shù)字的重要性。

  1. $ ls -l
  2. total 0
  3. drwx------ 5 shs shs 120 Jun 16 12:44 1000
  4. drwx------ 5 dory dory 120 Jun 16 16:14 1002
  5. drwx------ 8 gdm gdm 220 Jun 14 12:18 121

我們看到每個(gè)目錄與當(dāng)前登錄的用戶或顯示管理器 gdm 相關(guān)。數(shù)字代表他們的 UID。每個(gè)目錄的內(nèi)容都是運(yùn)行中的進(jìn)程所使用的文件。

/run/user 文件只是你在 /run 中找到的一小部分。還有很多其他文件。有一些文件包含了各種系統(tǒng)進(jìn)程的進(jìn)程 ID。

  1. $ ls *.pid
  2. acpid.pid atopacctd.pid crond.pid rsyslogd.pid
  3. atd.pid atop.pid gdm3.pid sshd.pid

如下所示,上面列出的 sshd.pid 文件包含 ssh 守護(hù)程序(sshd)的進(jìn)程 ID。

  1. $ cat sshd.pid
  2. 1148
  3. $ ps -ef | grep sshd
  4. root 1148 1 0 Jun14 ? 00:00:00 /usr/sbin/sshd -D <==
  5. root 10784 1148 0 12:44 ? 00:00:00 sshd: shs [priv]
  6. shs 10922 10784 0 12:44 ? 00:00:00 sshd: shs@pts/0
  7. root 18109 1148 0 16:13 ? 00:00:00 sshd: dory [priv]
  8. dory 18232 18109 0 16:14 ? 00:00:00 sshd: dory@pts/1
  9. shs 19276 10923 0 16:50 pts/0 00:00:00 grep --color=auto sshd

/run 中的某些子目錄只能使用 root 權(quán)限訪問(wèn),例如 /run/sudo。例如,以 root 身份運(yùn)行我們可以看到一些與真實(shí)或嘗試使用 sudo 相關(guān)的文件:

  1. /run/sudo/ts# ls -l
  2. total 8
  3. -rw------- 1 root dory 112 Jun 16 16:37 dory
  4. -rw------- 1 root shs 168 Jun 17 08:33 shs

為了與 /run 的變化保持一致,一些運(yùn)行時(shí)數(shù)據(jù)的舊位置現(xiàn)在是符號(hào)鏈接。/var/run 現(xiàn)在是指向 /run 的指針,/var/lock 指向 /run/lock 的指針,可以保證舊的引用按預(yù)期工作。

  1. $ ls -l /var
  2. total 52
  3. drwxr-xr-x 2 root root 4096 Jun 17 07:36 backups
  4. drwxr-xr-x 19 root root 4096 Apr 18 13:46 cache
  5. drwxrwsrwt 2 root whoopsie 4096 Jun 13 07:39 crash
  6. drwxr-xr-x 75 root root 4096 Jun 9 15:14 lib
  7. drwxrwsr-x 2 root staff 4096 Oct 16 2017 local
  8. lrwxrwxrwx 1 root root 9 May 14 2018 lock -> /run/lock
  9. drwxrwxr-x 17 root syslog 4096 Jun 17 00:00 log
  10. drwxrwsrwt 2 root mail 4096 Jun 13 12:10 mail
  11. drwxrwsrwt 2 root whoopsie 4096 Jan 5 2018 metrics
  12. drwxr-xr-x 2 root root 4096 Jan 5 2018 opt
  13. lrwxrwxrwx 1 root root 4 May 14 2018 run -> /run
  14. drwxr-xr-x 9 root root 4096 Jun 16 2018 snap
  15. drwxr-xr-x 9 root root 4096 Jun 9 15:14 spool
  16. drwxrwxrwt 8 root root 4096 Jun 17 00:00 tmp
  17. drwxr-xr-x 3 root root 4096 Jan 19 12:14 www

雖然技術(shù)上的變化很小,但轉(zhuǎn)換到使用 /run 只是為了在 Linux 文件系統(tǒng)中更好地組織運(yùn)行時(shí)數(shù)據(jù)。

責(zé)任編輯:龐桂玉 來(lái)源: Linux中國(guó)
相關(guān)推薦

2020-08-11 09:47:30

JS閉包代碼

2009-07-03 18:59:02

2010-06-13 13:43:30

Linux超級(jí)計(jì)算機(jī)

2009-01-03 11:07:06

AJAXASP.NET.NET

2016-07-05 10:53:56

2019-07-29 19:30:54

Linux命令ls命令

2019-10-10 08:42:37

Linux內(nèi)核操作系統(tǒng)

2020-03-11 16:40:59

Linux內(nèi)核代碼

2019-08-15 16:00:21

Linux內(nèi)核Kconfig

2010-03-24 09:25:01

移動(dòng)數(shù)據(jù)中心

2021-06-08 08:33:33

Zabbix5.2snmptrap探索運(yùn)維

2009-08-27 11:43:46

ibmdw云計(jì)算

2014-08-28 10:18:36

LinuxShebang

2019-10-22 08:30:26

LinuxFHS進(jìn)程

2011-07-22 09:40:39

2010-05-25 09:44:03

2017-09-07 12:56:24

Linux系統(tǒng)結(jié)構(gòu)

2025-04-03 03:55:00

2011-04-01 09:58:35

Linux 發(fā)行版

2015-11-25 09:41:05

數(shù)據(jù)中心
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)