1

I have a program x which sometimes crashes on certain input files.

How do I write a bash script that returns the following?

  • 0 if the program x terminates fine or runs for longer than 1/20th of a second
  • 1 if the program x segfaults

Note that the program will segfault or run forever, so I need to stop it somehow with the script. can you show me please

Thank you for any ideas

0

2 Answers 2

2

Most of the programs when they do not terminate correctly return 0. That information can be gleaned from the bash variable $?. So, after you run the program, check if $? is 0. If it is, the program ran successfully. Otherwise, there was a problem.

This is, of course, assuming that the program is following proper conventions.

Sign up to request clarification or add additional context in comments.

2 Comments

The program will segfault or run forever, so I need to stop it somehow with the script. can you show me please
You can use timeout to stop a program after n seconds.
1

echo $? should let you know whether or not the program succeeded.

http://www.devshed.com/c/a/BrainDump/Executing-Commands-with-bash/1/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.