Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting meaning of system() function's return value in Linux

When I execute a command using system(COMMAND) function in C++ code running on Linux, the return values of calls of system(COMMAND) are not same from each other. Do we have any ways to detect segmentation fault or abnormal termination by using return value of system(COMMAND) function?

For example, when I got segmentation fault after executing a command by using system function, I confirmed the return value of that function was 35584. However, I could not know what that return value means, and I am not sure all possible segmentation faults return 35584. Is there a way to detect all possible values of return values when I encounter segmentation fault or abnormal termination?

like image 203
freddy Avatar asked Feb 17 '23 22:02

freddy


1 Answers

man 3 system refers to man 2 wait for the meaning of return value. The latter page describes several macros usable with this value, notably WIFSIGNALED(status) and WTERMSIG(status). That's what you can use to check for segmentation fault or termination on other signals.

like image 175
Anton Kovalenko Avatar answered Feb 27 '23 09:02

Anton Kovalenko