0

A cron job is created, and in the cron job contains the following code:

int flag = system("path/main");
printf("system return value: %d \n", flag);

the cron job excute every day, and the "flag" is usually "0", However sometimes "falg" is "32512".

I have google the error code, it means "command is not found".

But I need your help to enlighten me, why sometime is ok, sometimes is not. Does it matter with the relative directory "path/main"

iceKing
  • 147
  • 3
  • 13
  • We would need more details about that "sometimes". Perhaps the job is being executed in a different policy/by a different user. – Bartek Banachewicz Oct 08 '13 at 14:04
  • Sorry for lack of information. I haven't found any law about "sometimes" yet. Sorry for it. – iceKing Oct 08 '13 at 14:23
  • [system(3)](http://man7.org/linux/man-pages/man3/system.3.html) is returning the status given by [waitpid(2)](http://man7.org/linux/man-pages/man2/waitpid.2.html). Read both man pages I linked to. – Basile Starynkevitch Oct 18 '13 at 07:24

1 Answers1

1

The return code is a bitmask of several things (see for example this question). In your case it suggests an exit code of 255 (which is purely from your child process, not due to signal). You should check your main program.

Community
  • 1
  • 1
Alexander L. Belikoff
  • 5,698
  • 1
  • 25
  • 31
  • 32512=127*256, so the return code of shell is 127. it means “the command was not found” – iceKing Oct 08 '13 at 14:33
  • Thanks for your help. I would like to check code more carefully. ^_^ – iceKing Oct 08 '13 at 14:35
  • @iceKing: If the call to `system()` did not return `-1` and `127 == WEXITSTATUS(flag)` then either the shell (`bin/sh`) which should have executed the *program* passed to `system()` had not been found **or** the *program* itself returned `127`. There is clear ambiguity with this value. – alk Oct 08 '13 at 15:04
  • Thanks for your suggestions. I reviewed my code carefully, and found that , in a logic, it will change the work directory, so invoking system will return error. Thanks. – iceKing Oct 09 '13 at 02:56