While trying to test something unconnected, I launched an infinite loop on my terminator
terminal emulator which printed a lot of data to STDOUT. After running it for a few minutes, I noticed that my /tmp
partition was full.
$ df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 68G 21G 44G 33% /
udev 10M 0 10M 0% /dev
tmpfs 800M 1.2M 799M 1% /run
/dev/disk/by-uuid/e29c6006c5c6 68G 21G 44G 33% /
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.2G 140K 3.2G 1% /run/shm
/dev/sda6 290G 204G 72G 75% /home
/dev/sda3 79G 51G 28G 65% /winblows
tmpfs 3.2G 3.2G 0G 100% /tmp
However, du
showed the directory to be empty:
$ du -sch /tmp/
0 /tmp/
0 total
Running rm -rf /tmp
made no difference either. All this occupied space was freed when I closed the terminal that was running the loop so I guess that it was taken up by the scrollback information of the terminal.
I know that tmpfs is a storage facility designed to mimic a filesystem. OK but
-
How does this work? Is
/tmp
a file somewhere (yes, I know that "everything is a file"), I mean is it a "normal" file stored somewhere on the hard drive? Is it a part of my swap partition? Of my RAM? If I understand correctly, it can be either in RAM or SWAP depending on current usage but I saw no spikes in RAM or SWAP usage while/tmp
was full. -
Where/how is the scrollback information from the terminal kept? Since there were no files in
/tmp
it cannot be stored in a simple text file, so where is it and how come it is taking up space on/tmp
?
Best Answer
I’m not specifically expert in
tmpfs
, and I’ve never heard of yourterminator
terminal emulator, but I can address the general question. This is an old Unix trick: create a file (commonly, but not necessarily, in/tmp
) and then promptly delete it. As long as you keep it open, it continues to exist, and resides on the filesystem (be it disk, memory, local, or remote), and you can write to it and read from it, just like any ordinary file1, until you close it. Then it is really deleted.____________
1 Except for the fact that it doesn’t appear in any directory. You can think of it as an ordinary file that happens to have zero hard links to it.