There has been a small but significant change in the way the Linux system works with runtime data.
If you haven't paid close attention, you may not have noticed some small but significant changes in the way the Linux system works with runtime data. It reorganized the accessible ways and locations in the file system, and this change began about eight years ago. Although this change may not be enough to make your socks wet, it provides more consistency in the Linux file system and is worth exploring.
To get started, go to /run
. If you use df
to check it, you will see this output:
$ df -k .
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 609984 2604 607380 1% /run
复制代码
It is recognized as "tmpfs" (temporary file system), so we know that /run
files and directories are not stored on disk, but only stored in memory. They represent data stored in memory (or disk-based swap space). It looks like a mounted file system, which can make it easier to access and manage.
/run
It is home to all kinds of data. For example, if you look at it /run/user
, you will notice a set of directories with numerical names.
$ ls /run/user
1000 1002 121
复制代码
Use a long list of files to discover the importance of these numbers.
$ ls -l
total 0
drwx------ 5 shs shs 120 Jun 16 12:44 1000
drwx------ 5 dory dory 120 Jun 16 16:14 1002
drwx------ 8 gdm gdm 220 Jun 14 12:18 121
复制代码
We see that each directory is related to the currently logged-in user or the display manager gdm. The numbers represent their UID. The contents of each directory are files used by the running process.
/run/user
File you just /run
find in a small part. There are many other files. Some files contain process IDs of various system processes.
$ ls *.pid
acpid.pid atopacctd.pid crond.pid rsyslogd.pid
atd.pid atop.pid gdm3.pid sshd.pid
复制代码
As shown below, the above-listed sshd.pid
file contains ssh daemon ( sshd
) of the process ID.
$ cat sshd.pid
1148
$ ps -ef | grep sshd
root 1148 1 0 Jun14 ? 00:00:00 /usr/sbin/sshd -D <==
root 10784 1148 0 12:44 ? 00:00:00 sshd: shs [priv]
shs 10922 10784 0 12:44 ? 00:00:00 sshd: shs@pts/0
root 18109 1148 0 16:13 ? 00:00:00 sshd: dory [priv]
dory 18232 18109 0 16:14 ? 00:00:00 sshd: dory@pts/1
shs 19276 10923 0 16:50 pts/0 00:00:00 grep --color=auto sshd
复制代码
/run
Some subdirectories in can only be accessed with root privileges, for example /run/sudo
. For example, run as root, we can see some real or try to use the sudo
relevant files:
/run/sudo/ts# ls -l
total 8
-rw------- 1 root dory 112 Jun 16 16:37 dory
-rw------- 1 root shs 168 Jun 17 08:33 shs
复制代码
In order to /run
change consistent runtime data of some old location it is now a symbolic link. /var/run
Now is the point /run
pointer /var/lock
pointing to /run/lock
the pointer, you can ensure that the old reference works as expected.
$ ls -l /var
total 52
drwxr-xr-x 2 root root 4096 Jun 17 07:36 backups
drwxr-xr-x 19 root root 4096 Apr 18 13:46 cache
drwxrwsrwt 2 root whoopsie 4096 Jun 13 07:39 crash
drwxr-xr-x 75 root root 4096 Jun 9 15:14 lib
drwxrwsr-x 2 root staff 4096 Oct 16 2017 local
lrwxrwxrwx 1 root root 9 May 14 2018 lock -> /run/lock
drwxrwxr-x 17 root syslog 4096 Jun 17 00:00 log
drwxrwsrwt 2 root mail 4096 Jun 13 12:10 mail
drwxrwsrwt 2 root whoopsie 4096 Jan 5 2018 metrics
drwxr-xr-x 2 root root 4096 Jan 5 2018 opt
lrwxrwxrwx 1 root root 4 May 14 2018 run -> /run
drwxr-xr-x 9 root root 4096 Jun 16 2018 snap
drwxr-xr-x 9 root root 4096 Jun 9 15:14 spool
drwxrwxrwt 8 root root 4096 Jun 17 00:00 tmp
drwxr-xr-x 3 root root 4096 Jan 19 12:14 www
复制代码
Although technically a little change, but the conversion to use /run
just to better organize runs on Linux file system data.
Author: Linux Chinese
link: https: //juejin.cn/post/6844903873346273294