在我对输出文件执行 "rm" 之后,C 程序在哪里写入输出?
Where does a C program write output after I did "rm" on the output file?
我 运行 计算集群上的一个相当讨厌的 C 程序 运行 Redhat 进入了一个无限循环,在每个循环中打印一行输出。当我意识到它正在快速创建一个最终会用完所有磁盘 space 的文件时,我在终止程序之前对该输出文件 运行 "rm" 进行了处理。不幸的是,在我最终终止程序之前,per "df -h" space 继续在驱动器上用完。
我现在找不到写入的文件,所以我无法删除它。这样的文件会写到哪里?
杀死程序应该释放磁盘space。在此之前,该文件与其文件夹的链接已解除,但只要它处于主动打开状态,它就不会停止存在(作为 inode)。
检查ls -l /proc/<pid>/fd
以查看文件是什么;本质上,内核所知道的关于该进程的一切都在 /proc/<pid>
.
中的某个地方
在此处阅读更多有关如何处理这些问题的信息:
https://unix.stackexchange.com/questions/68523/find-and-remove-large-files-that-are-open-but-have-been-deleted
正在写入您删除的文件。
根据 unlink(3) 的手册页:
The unlink() function shall remove a link to a file. If path names a
symbolic link, unlink() shall remove the symbolic link named by path
and shall not affect any file or directory named by the contents of
the symbolic link. Otherwise, unlink() shall remove the link named by
the pathname pointed to by path and shall decrement the link count of
the file referenced by the link.
When the file's link count becomes 0 and no process has the file open,
the space occupied by the file shall be freed and the file shall no
longer be accessible. If one or more processes have the file open when
the last link is removed, the link shall be removed before unlink()
returns, but the removal of the file contents shall be postponed until
all references to the file are closed.
在Unix/Linux中,文件是一种数据结构(在磁盘上)。只要系统中存在对此的指针(或引用,见下文),数据就不会被删除。然而,一旦不再有指针,它就是。
指针基本上可以让程序打开文件。一旦程序(或这些程序)终止,这个指针就失效了。
指针也可以是文件系统目录中的一个条目。这将是您使用 ls
或在图形文件管理器中看到的条目。所以,一旦你删除了这个条目,that 指针也被删除了,但没有其他!请注意,在(同一)文件系统中可以有多个这样的条目。这些被称为硬链接(许多(指针)到一个(文件)关系)。
实际上,文件会计算所有这些引用(对于目录 entries/hardlinks 永久保存在磁盘上,对于打开的文件(“文件句柄”)保存在系统内存中)。后者会为每个打开的文件占用宝贵的系统内存,并且文件最常被关闭并且应该尽快关闭的原因之一。
因此,一旦所有指针都被删除,该文件将无法再访问,因此将被删除。这被称为 垃圾收集(如果这是现在发明的,它可能被称为 "memory recycling")顺便说一句。类似于 Java 和 Python 等语言对未使用的对象所做的。
之所以叫它"pointer"是因为相似:它实际上是一个名为"inode"的数据结构的特定索引(地址),其中它点,而不是目录条目。
我 运行 计算集群上的一个相当讨厌的 C 程序 运行 Redhat 进入了一个无限循环,在每个循环中打印一行输出。当我意识到它正在快速创建一个最终会用完所有磁盘 space 的文件时,我在终止程序之前对该输出文件 运行 "rm" 进行了处理。不幸的是,在我最终终止程序之前,per "df -h" space 继续在驱动器上用完。
我现在找不到写入的文件,所以我无法删除它。这样的文件会写到哪里?
杀死程序应该释放磁盘space。在此之前,该文件与其文件夹的链接已解除,但只要它处于主动打开状态,它就不会停止存在(作为 inode)。
检查ls -l /proc/<pid>/fd
以查看文件是什么;本质上,内核所知道的关于该进程的一切都在 /proc/<pid>
.
在此处阅读更多有关如何处理这些问题的信息: https://unix.stackexchange.com/questions/68523/find-and-remove-large-files-that-are-open-but-have-been-deleted
正在写入您删除的文件。
根据 unlink(3) 的手册页:
The unlink() function shall remove a link to a file. If path names a symbolic link, unlink() shall remove the symbolic link named by path and shall not affect any file or directory named by the contents of the symbolic link. Otherwise, unlink() shall remove the link named by the pathname pointed to by path and shall decrement the link count of the file referenced by the link.
When the file's link count becomes 0 and no process has the file open, the space occupied by the file shall be freed and the file shall no longer be accessible. If one or more processes have the file open when the last link is removed, the link shall be removed before unlink() returns, but the removal of the file contents shall be postponed until all references to the file are closed.
在Unix/Linux中,文件是一种数据结构(在磁盘上)。只要系统中存在对此的指针(或引用,见下文),数据就不会被删除。然而,一旦不再有指针,它就是。
指针基本上可以让程序打开文件。一旦程序(或这些程序)终止,这个指针就失效了。
指针也可以是文件系统目录中的一个条目。这将是您使用 ls
或在图形文件管理器中看到的条目。所以,一旦你删除了这个条目,that 指针也被删除了,但没有其他!请注意,在(同一)文件系统中可以有多个这样的条目。这些被称为硬链接(许多(指针)到一个(文件)关系)。
实际上,文件会计算所有这些引用(对于目录 entries/hardlinks 永久保存在磁盘上,对于打开的文件(“文件句柄”)保存在系统内存中)。后者会为每个打开的文件占用宝贵的系统内存,并且文件最常被关闭并且应该尽快关闭的原因之一。
因此,一旦所有指针都被删除,该文件将无法再访问,因此将被删除。这被称为 垃圾收集(如果这是现在发明的,它可能被称为 "memory recycling")顺便说一句。类似于 Java 和 Python 等语言对未使用的对象所做的。
之所以叫它"pointer"是因为相似:它实际上是一个名为"inode"的数据结构的特定索引(地址),其中它点,而不是目录条目。