I am on ubuntu linux 10.04
I have the following
#simplec.c
#include "stdio.h"
int main()
{
printf("Hello World\n");
system("ps -H");
return 12;
}
AND
#callsimplec.c
#include "stdio.h"
int main()
{
int ret =0;
ret = system("./simplec");
printf("In callsimplec ret is %d\n", ret);
}
When I do
gcc callsimplec.c -o callsimplec
gcc simplec.c -o simplec
./callsimplec
I get:
Hello World
PID TTY TIME CMD
27238 pts/2 00:00:00 bash
28066 pts/2 00:00:00 callsimplec
28067 pts/2 00:00:00 simplec
28068 pts/2 00:00:00 ps
In callsimplec ret is 3072
So I figured out that 3072 is printed because 256 times 12 is 3072. Whatever return value I use in simplec.c I get that value multiplied by 256 as the output in print. Why is that? I am just trying to make sense of it.
The value returned by
systemshould be used with the macros: WEXITED, WIFEXITSTATUS etc.The value returned by
system(and by thewaitfamily) is, acording to case:Normal termination:
Killed by signal:
Stopped by signal
Continued by signal
So in your case the process exited normally and system returned
12shifted 8 times.