▲ 218 ▼ An amazing directory: /proc (europe.pub) submitted 3 months ago by cm0002@europe.pub to c/linux@programming.dev 7 comments fedilink hide all child comments
[–] sik0fewl@piefed.ca 7 points 3 months ago (4 children) How can the symlinks work if the file has been deleted? permalink fedilink source hideshow 4 child comments replies: [–] princess@lemmy.blahaj.zone 11 points 3 months ago (3 children) They aren't symbolic links. They're closer to hard links, IIRC, in that they share the inode with other file paths. ofc /proc isn't a "real" file system so the metaphors break down a little; it's not backed by disk, it's a view into the kernel's process information exposed as a file system permalink fedilink source parent hideshow 3 child comments replies: [–] trem@lemmy.blahaj.zone 11 points 3 months ago (1 child) Just to kind of confirm this: ls -l does not show them like hard links, but rather like soft/symbolic links. But when I do tail -f /path/to/file.txt on a file (to keep it open in a process) and then delete the file, I get this output in ls -l: 3 -> '/path/to/file.txt (deleted)' The 3 seems to just be an incrementing number for each file opened by the process. And then, well, obviously the file isn't now called "file.txt (deleted)". That is just a name the kernel makes up when ls -l asks it what's in that directory. So, presumably the kernel keeps a separate copy of that file in memory until the process closes the file or is terminated. And then exposes it through this pseudo-softlink rather than making use of hardlinks. permalink fedilink source parent hideshow 1 child comment replies: [–] korthrun@piefed.social 7 points 3 months ago* The 3 seems to just be an incrementing number for each file opened by the process. FWIW: https://en.wikipedia.org/wiki/File_descriptor#file_descriptor_table If you throw an strace on a process that interacts with the filesystem you'll see that stuff like open() returns a file descriptor and stuff like read() takes a file descriptor as an argument. These are also generally the numbers you're using when you do I/O redirection in your shell with stuff like 2>&1 or exec 5< ./some_file.txt permalink fedilink source parent [–] sik0fewl@piefed.ca 4 points 3 months ago Ya, the description sounds more like a hard link, but that also doesn’t work, since the executable is obviously not stored on /proc. Your explanation makes sense, thanks. permalink fedilink source parent
[–] princess@lemmy.blahaj.zone 11 points 3 months ago (3 children) They aren't symbolic links. They're closer to hard links, IIRC, in that they share the inode with other file paths. ofc /proc isn't a "real" file system so the metaphors break down a little; it's not backed by disk, it's a view into the kernel's process information exposed as a file system permalink fedilink source parent hideshow 3 child comments replies: [–] trem@lemmy.blahaj.zone 11 points 3 months ago (1 child) Just to kind of confirm this: ls -l does not show them like hard links, but rather like soft/symbolic links. But when I do tail -f /path/to/file.txt on a file (to keep it open in a process) and then delete the file, I get this output in ls -l: 3 -> '/path/to/file.txt (deleted)' The 3 seems to just be an incrementing number for each file opened by the process. And then, well, obviously the file isn't now called "file.txt (deleted)". That is just a name the kernel makes up when ls -l asks it what's in that directory. So, presumably the kernel keeps a separate copy of that file in memory until the process closes the file or is terminated. And then exposes it through this pseudo-softlink rather than making use of hardlinks. permalink fedilink source parent hideshow 1 child comment replies: [–] korthrun@piefed.social 7 points 3 months ago* The 3 seems to just be an incrementing number for each file opened by the process. FWIW: https://en.wikipedia.org/wiki/File_descriptor#file_descriptor_table If you throw an strace on a process that interacts with the filesystem you'll see that stuff like open() returns a file descriptor and stuff like read() takes a file descriptor as an argument. These are also generally the numbers you're using when you do I/O redirection in your shell with stuff like 2>&1 or exec 5< ./some_file.txt permalink fedilink source parent [–] sik0fewl@piefed.ca 4 points 3 months ago Ya, the description sounds more like a hard link, but that also doesn’t work, since the executable is obviously not stored on /proc. Your explanation makes sense, thanks. permalink fedilink source parent
[–] trem@lemmy.blahaj.zone 11 points 3 months ago (1 child) Just to kind of confirm this: ls -l does not show them like hard links, but rather like soft/symbolic links. But when I do tail -f /path/to/file.txt on a file (to keep it open in a process) and then delete the file, I get this output in ls -l: 3 -> '/path/to/file.txt (deleted)' The 3 seems to just be an incrementing number for each file opened by the process. And then, well, obviously the file isn't now called "file.txt (deleted)". That is just a name the kernel makes up when ls -l asks it what's in that directory. So, presumably the kernel keeps a separate copy of that file in memory until the process closes the file or is terminated. And then exposes it through this pseudo-softlink rather than making use of hardlinks. permalink fedilink source parent hideshow 1 child comment replies: [–] korthrun@piefed.social 7 points 3 months ago* The 3 seems to just be an incrementing number for each file opened by the process. FWIW: https://en.wikipedia.org/wiki/File_descriptor#file_descriptor_table If you throw an strace on a process that interacts with the filesystem you'll see that stuff like open() returns a file descriptor and stuff like read() takes a file descriptor as an argument. These are also generally the numbers you're using when you do I/O redirection in your shell with stuff like 2>&1 or exec 5< ./some_file.txt permalink fedilink source parent
[–] korthrun@piefed.social 7 points 3 months ago* The 3 seems to just be an incrementing number for each file opened by the process. FWIW: https://en.wikipedia.org/wiki/File_descriptor#file_descriptor_table If you throw an strace on a process that interacts with the filesystem you'll see that stuff like open() returns a file descriptor and stuff like read() takes a file descriptor as an argument. These are also generally the numbers you're using when you do I/O redirection in your shell with stuff like 2>&1 or exec 5< ./some_file.txt permalink fedilink source parent
[–] sik0fewl@piefed.ca 4 points 3 months ago Ya, the description sounds more like a hard link, but that also doesn’t work, since the executable is obviously not stored on /proc. Your explanation makes sense, thanks. permalink fedilink source parent