- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
背景:
在 CentOS 7 x86_64 上。我正在使用 applydeltarpm
,并且在从 delta 创建新的 RPM 时磁盘空间不足。我看到 /
磁盘空间使用量在应用过程中增加到 100%,但无法使用 ls -l/tmp
或找到/tmp -mmin -1 -type f
。
我更改了 applydeltarpm
源代码以使用 /var/tmp
而不是 /tmp
,并重建了 RPM。现在 apply 使用修改后的 applydeltarpm
,因为 /var/tmp
有更多的磁盘空间。但是我仍然找不到用 mkstemp64
创建的临时文件。
问题:
mkstemp64
创建的临时文件似乎“不存在”,但对于创建者来说仍然作为文件描述符存在,并且在 applydeltarpm
时占用了大量磁盘空间> 创建一个大的 RPM(在慢速磁盘上应用 1 小时)。 mkstemp64
文档说创建了一个实际文件。源代码显示模板文件名为/tmp/deltarpmpageXXXXXX
。但是不存在具有该模板名称的文件。
这个临时文件如何能够在系统上创建而不用通常的目录列表 ls
或 find
找到。如何在系统中找到这些“不存在”的文件?
(我很好奇,因为我也在监控系统安全)
引用资料:
https://github.com/rpm-software-management/deltarpm/blob/master/applydeltarpm.c
# line 198
if (pagefd < 0)
{
char tmpname[80];
sprintf(tmpname, "/tmp/deltarpmpageXXXXXX");
#ifdef DELTARPM_64BIT
pagefd = mkstemp64(tmpname);
#else
pagefd = mkstemp(tmpname);
#endif
if (pagefd < 0)
{
fprintf(stderr, "could not create page area\n");
exit(1);
}
unlink(tmpname);
}
https://www.mkssoftware.com/docs/man3/mkstemp.3.asp
The mktemp() function returns a unique file name based on the template parameter. At the time it is generated, no file in the current directory has that name. No file is actually created, so it is possible that another application could create a file with this name.
The mkstemp() function is similar to mktemp() in that it create a unique file name based on template; however, mkstemp() actually creates the file and returns its file descriptor. The name of the created file is stored in template.
The mkstemp64() function is identical to the mkstemp() function except that the file is opened with the O_LARGEFILE flag set.
最佳答案
如果不再需要通过文件系统访问临时文件,通常的做法是在创建后立即取消链接。如果进程崩溃或稍后忘记取消链接,这可以避免临时文件悬空。
unlink()
不会删除文件,它只会从文件系统中删除文件的链接。文件系统中文件的每个链接都会将文件的链接计数增加一个(可以有多个链接指向同一个文件)。此外,调用 open()
或 mmap()
打开文件的每个进程都会增加文件计数,直到它关闭描述符 - 然后链接计数会减少。只要至少有一个链接,文件就存在。当链接计数达到零时,文件实际上被删除。
mkstemp()
还在幕后调用 open()
以打开临时文件并返回其描述符。
为了查看已打开但文件系统中不再存在的文件,您可以使用lsof。并搜索文件名后有“(已删除)”的行。
lsof | grep '(deleted)'
当它们所附加的进程完成或自行关闭文件描述符时,这些文件使用的(磁盘)空间将被释放。
关于Linux - mkstemp64 如何创建隐藏文件,我如何在文件系统中看到它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45760956/
我的 mkstemp() 函数有问题。 cygwin 上的 GCC 编译器生成警告: implicit declaration of function ‘mkstemp‘ GCcflags:-std=
使用 mkstemp 创建的临时文件是否已同步到磁盘? 这是我所拥有的: 程序使用mkstemp创建临时文件并将fd发送到另一个程序。 此临时文件由两个程序 mmap 处理,并且使用频繁(高达 400
我在 C 中调用以下代码: fileCreatefd = mkstemp(fileName); 我看到该文件是使用权限 600 (-rw--------) 创建的。我想将此临时文件创建为 -rw-r
我在一个循环(超过 10 000 次)中使用 subprocess.run 来调用一些 java 命令。像这样: import subprocess import tempfile for i
当使用 mkstemp() 生成临时文件名时,立即对 mkstemp() 返回的文件描述符调用 close() 是否安全,将 mkstemp() 生成的文件名存储在某处并使用它(在很多情况下)稍后)再
我正在做一项作业,需要存储多个输出。这就会涉及到递归。如果我有多个使用 mkstemp() 的临时文件,我会遇到麻烦吗? 最佳答案 您可以打开任意数量的文件,最多可达打开文件数量的限制。请记住mkst
我正在使用 tempfile.mkstemp 生成一个随机可用的文件名并使用 os.fdopen 写入一些内容。然后我通过 celery 将文件名传递给任务。 此任务打开文件,处理内容,最后删除文件。
Java 中有什么方法可以安全地写入临时文件吗? 据我所知,创建临时文件 (createTempFile) 的唯一方法实际上不会同时打开它,因此文件打开和文件写入之间存在竞争条件。我错过了什么吗?我在
我正在使用 : 创建一个 tmp 文件 from tempfile import mkstemp 我正在尝试在这个文件中写入: tmp_file = mkstemp() file = open(tmp
mkstemp() 函数从模板生成一个唯一的临时文件名,创建并打开文件,并返回文件的打开文件描述符。模板的最后六个字符必须是“XXXXXX”,这些字符将替换为使文件名唯一的字符串。由于会被修改,tem
我正在尝试将 mkstemp 与 Python 3 结合使用: Python 3.2.3 (default, Jun 25 2012, 23:10:56) [GCC 4.7.1] on linux2
是否可以通过调用 mkstemp() 获取文件名(和路径)?如果"is",怎么做? 最佳答案 来自mkstemp manual page : The last six characters of te
我有一个调用 mkstemp() 的程序,用返回的 fd 写一些东西,然后关闭 fd。我希望文件一直保留到我自己删除它为止!使用诸如 rm 命令之类的东西。我的问题是:Linux 在 close(fd
根据 tempfile.mkstemp docs , mkstemp() returns a tuple containing an OS-level handle to an open file (
任何人都可以指出在 Win32 或非常接近的模拟上实现 mkstemp() (C/C++) 的代码。 必须是无种族的。 应该是这样的 #include #include // port of mk
看来我完全误用了mkstemp。无论我如何使用它,我总是会遇到段错误。我用 gcc -ggdb -Wall -Werror main.c 编译了下面最基本的程序并用 ./a.out 运行它 #incl
任何人都可以指出在 Win32 或非常接近的模拟上实现 mkstemp() (C/C++) 的代码。 必须是无种族的。 应该是这样的 #include #include // port of mk
在我的机器上,Linux 机器 ulimit -n 给出 1024。这段代码: from tempfile import mkstemp for n in xrange(1024 + 1):
我正在自动生成文件名,并且我不希望发生覆盖。我正在懒惰地使用这一小行代码 fd, filepath = tempfile.mkstemp(ext, prefix='odt_img_', dir=sel
我无法从 mkstemp 返回的句柄写入由 fdopen 打开为 rw 的文件。 >>> import tempfile >>> import os >>> a = tempfile.mkstemp(
我是一名优秀的程序员,十分优秀!