W
W
waltaki2019-08-16 00:44:08
linux
waltaki, 2019-08-16 00:44:08

What is the directory /proc, /tmp?

Hello.
I have a number of questions about this.
1) If / proc does not store information not on the disk, not in frames, then where at all? I don't understand(
2) For example, I'm in bash. Is it possible somehow to get my output by looking in the /proc folder of the bash process?
3) If the /tmp folder is stored in RAM, can I store my temporary files there for instant access?
4) How can I implement this: There is a file in which information is constantly written so that it does not take up much space, I set a conditional limit of 10000kb, when the file starts to weigh more, the difference will be erased from the beginning of the file. For example, a file (limited to 10 bytes): f.test
1234567890
For example, I write echo 10 >> f.test into it,
now in the file: Is
3456789010
it possible to implement this, without task crons?
Tell me, just curious))

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Saboteur, 2019-08-16
@saboteur_kiev

1) If / proc does not store information not on the disk, not in frames, then where at all? I don’t understand (
/proc is generally an abstraction. The kernel of the system knows which processes are currently running and stores it in memory. And in /proc visualizes this, providing some interface in the form of “everything is a file.” You just need to understand that this is not ext2 / ext3 / ext4 emulated in memory, this is exactly procfs
2) For example, I'm in bash. Is it possible somehow to get my output by looking in the /proc folder of the bash process?
yes, you can connect to your stdout, which /proc/<PID>/fd/1
you can actually see how you connected and where yours is looking /proc/<PID>/fd/1(most likely to some thread /dev/pts/0) and watch from there too.
3) If the /tmp folder is stored in RAM, can I store my temporary files there for instant access?
Yes. You just need to remember that tmpfs is not limited, that is, the more you put there, the less free RAM remains
4) How can I implement this: There is a file in which information is constantly written so that it does not take up much space, I set a conditional limit of 10000kb , when the file starts to weigh more, the difference will be erased from the beginning of the file.
You need to understand that you cannot erase 10 bytes from the beginning of the file, because you need to shift the contents of the entire file. In other words, the entire file will have to be overwritten.
Therefore, another method is used - log rotate - when writing to a file, its size is checked. If it exceeds the value, the file is renamed (for example, to file.log.1) and a new file file.log is opened
You can control how many files can be in the list and don't forget to rename all files to match the order. But this needs to be done by the one who writes to the file.

K
Karpion, 2019-08-16
@Karpion

tmpfs is usually stored in RAM, but can be swapped to disk if there is not enough memory. Its main property is the absence of transactional methods of work required by a normal file system - this gives speed, and reliability is not needed there, because it is cleaned during reboot.
You can and should store your files there. But we must remember: "when rebooting, it is cleaned."
procfs is not stored anywhere, but generated on the fly. I explain very roughly:
When the ls command looks at a regular file system (addresses in a directory served by a regular file system), then the file system driver reads some kind of storage - usually an HDD / SSD. And there are file names - you can find them with a program like diskedit (if you know what it is).
When the ls command looks at the procfs root, the procfs driver does not read any media, but runs the ps command inside itself (lovers of correct formulations will now throw slippers at me). ps reads the list of running processes (which is actually stored in memory - in kernel data) and passes it to the procfs driver. And the procfs driver generates a list of process numbers based on this information.
If the ls command looks into the procfs subdirectory, then the procfs driver takes information from the kernel data specifically about this process; this information also lies in memory, also in the kernel data.
Actually, the difference is that the driver of a conventional file system reads the data as they are - therefore it does it strictly in exclusive mode, no one else has the right to touch them. And the procfs driver works with data that the kernel can change at any time - and therefore does not read it from the storage location, but requests it through the "storekeeper" - through the same one through which the ps program and its "relatives" request this data.
And there is another interesting file system: devfs for the /dev directory ...

S
SOTVM, 2019-08-16
@sotvm

1) in tmpfs RAM
2) I didn’t understand the question
3) you can, if you have rights
4) but I don’t know / I don’t know how, it will shit in swap, and if the screw is not ssd, then I will have brakes
/ tmp and the browser cache is mounted into the RAM

V
Vitsliputsli, 2019-08-16
@Vitsliputsli

1) in /proc, a virtual file system is usually mounted giving access to various information and resources provided by the kernel.
2) you can, if you have permissions, see tty devices, or something like that.
3) you can if you have rights.
4) operating system and file system limits do not control the contents of files. But depending on the task, it can be solved, for example, using a pipe, or rotation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question