gpt4 book ai didi

c++ - 在我的场景中,什么可能导致解压缩命令返回 -1?

转载 作者:IT王子 更新时间:2023-10-29 01:00:11 25 4
gpt4 key购买 nike

我通过 C++ 代码中的 system() 调用运行解压缩,格式如下:

/usr/bin/unzip -o -q /<my_path_to_zip_file>/cfg_T-KTMAKUCB.zip -d /<my_path_to_dest>/../

这将近 90% 的时间成功。我无法理解是什么导致它时不时地以 -1 返回码失败。有什么想法吗?

最佳答案

根据我本地的man系统

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 的联机帮助页列出了各种返回码,但 -1 不在其中。

如果命令本身不能返回 -1,问题可能出在初始的 fork/exec 上,因为系统范围或每个 -用户限制(内存耗尽;进程表已满;用户的最大进程、打开文件或 VM 大小限制等)。

system 失败时,您应该检查 errno。在 strace -f 下运行整个过程也会显示发生的情况。

关于c++ - 在我的场景中,什么可能导致解压缩命令返回 -1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43049308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com