Skip to content
Advertisement

how to interpret pclose() status when popen() fails?

My application running on embedded linux (busybox) tries to execute a script via popen(cmd, "r").
cmd = "sh /tmp/DF1_05/update.sh DF1_05"

I can execute this script without problem launching it by hand from sh, but it fails when it’s launched by the application.
The first lines of update.sh script are:

JavaScript

I cannot even see the echo ouput.

My application’s code is:

JavaScript

The application output is:

JavaScript

So according to popen man page, pclose outputs a status similar to what wait4 outputs and as WIFEXITED(ret) is true, WEXITSTATUS(ret) is the output status of the child …….
Ok but after that it’s a treasure hunt for me and in fact, I cannot interpret what code 141 is.

Does anyone have more precise info?

Advertisement

Answer

I cannot interpret what code 141 is.

From man popen emphasis mine:

The popen() function opens a process by creating a pipe, forking, and invoking the shell.

From bash manual, which is a common convention:

When a command terminates on a fatal signal whose number is N, Bash uses the value 128+N as the exit status.

From man signal:

JavaScript

The process was terminated by SIGPIPE. SIGPIPE is 13 on your system. So your shell returned the exit status as 128 + 13 = 141.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement