在我的场景中,什么可能导致解压缩命令返回 -1?
What could cause unzip command returning -1 in my scenario?
我 运行 通过以下格式在我的 C++ 代码中调用 system()
解压缩:
/usr/bin/unzip -o -q /<my_path_to_zip_file>/cfg_T-KTMAKUCB.zip -d /<my_path_to_dest>/../
这将近 90% 的时间成功。我无法理解是什么导致它时常因 -1 return 代码而失败。有什么想法吗?
根据我的本地man system
,
The value returned is -1 on error (e.g. fork(2) failed), and the return status of the command otherwise.
并且 POSIX spec 说,
If a child process cannot be created, or if the termination status for the command language interpreter cannot be obtained, system() shall return -1 and set errno to indicate the error
最后,unzip
的联机帮助页列出了各种 return 代码,但 -1 不在其中。
如果命令本身不能 return -1,问题可能出在初始的 fork
/exec
,因为系统范围或每个用户限制(内存耗尽;进程 table 已满;用户的最大进程、打开文件或 VM 大小限制等)。
无论如何 system
失败时,您应该检查 errno
。 运行 strace -f
下的全部内容也会显示发生的情况。
我 运行 通过以下格式在我的 C++ 代码中调用 system()
解压缩:
/usr/bin/unzip -o -q /<my_path_to_zip_file>/cfg_T-KTMAKUCB.zip -d /<my_path_to_dest>/../
这将近 90% 的时间成功。我无法理解是什么导致它时常因 -1 return 代码而失败。有什么想法吗?
根据我的本地man system
,
The value returned is -1 on error (e.g. fork(2) failed), and the return status of the command otherwise.
并且 POSIX spec 说,
If a child process cannot be created, or if the termination status for the command language interpreter cannot be obtained, system() shall return -1 and set errno to indicate the error
最后,unzip
的联机帮助页列出了各种 return 代码,但 -1 不在其中。
如果命令本身不能 return -1,问题可能出在初始的 fork
/exec
,因为系统范围或每个用户限制(内存耗尽;进程 table 已满;用户的最大进程、打开文件或 VM 大小限制等)。
无论如何 system
失败时,您应该检查 errno
。 运行 strace -f
下的全部内容也会显示发生的情况。