c++ - System() 调用返回 255,但随后执行

标签 c++ shell system-calls qnx mongoose-web-server

我正在我的 qnx 系统上运行 mongoose 3.7 服务器。

我收到升级固件的http请求。根据要求,我使用 system()调用请求处理程序来升级固件。

但是,奇怪的是,system()返回 255。相同的调用之前在 mongoose 2.0 上也有效。

更奇怪的是,我通过 system() 发出的命令返回 255 后调用才起作用。

我正在使用WEXITSTATUS知道错误是system()返回

知道为什么会发生这种情况吗?

最佳答案

我发现了这个问题..

问题是发出 system() 命令的 Mongoose 回调线程不会等待返回状态,因为这一行:

在启动服务器线程的 mg_start() 函数中,他们包含了这一行:

mg_start() 第 5159 行:

(void) signal(SIGCHLD, SIG_IGN);

他们这样做是为了不创建僵尸进程。

引用号:http://www.win.tue.nl/~aeb/linux/lk/lk-5.html

但是,根据 QNX 文档,

“Setting a signal action to SIG_IGN for a signal that's pending causes the pending signal to be discarded, whether or not it is blocked. If a process sets the action for the SIGCHLD signal to SIG_IGN, the behavior is unspecified.”

SIGCHLD 上调用 SIG_IGN 会导致父进程忽略来自子进程的状态信号。

当我们进行 system() 调用时,它会阻止来自正在启动的 shell 的 SIGCHLD 信号。根据 UNIX 文档:

“Blocking SIGCHLD while waiting for the child to terminate prevents the application from catching the signal and obtaining status from system()'s child process before system() can get the status itself.”

但是,由于 mongoose 会丢弃该信号,因此它根本不会等待来自 system() 的信号。

它只是继续提供响应,而没有来自 system() 的有效返回状态。

我只是暂时注释掉了这一行。它正在发挥作用。

关于c++ - System() 调用返回 255,但随后执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18318521/

相关文章:

linux - 如何修复第 42 行 : [: too many arguments in Linux?

linux - 外部硬件设备可以使用系统调用吗?

linux - 如何通过内联汇编中的sysenter调用系统调用?

python - 在 Python 中进行系统调用

c++ - 通过 Rcpp 和 bit64 R 包将最大的 int64_t 变量值从 C++ 传递到 R

c++ - 收集实际使用的 C++ 代码行

shell - 为什么 sed 不替换重叠模式

java - XBee S1 通信问题

c++ - 函数 __gnu_cxx::__STL_next_prime(usigned long) 有什么作用?

linux - 在 bash 脚本中进行数学计算