简体   繁体   中英

Calling matlab with timeout function from a shell script

I have a pipeline of matlab codes, and one of the scripts will hang indefinitely under certain circumstances. Currently, I have a shell script that calls each piece of the pipeline. However, I would like to "timeout" the piece of matlab code that might hang indefinitely.

The below code works flawlessly if it is typed directly into a terminal window. However, when this code is a line in a shell script it will not execute the matlab script.

timeout --kill-after=25 25 matlab -nodisplay -nosplash -nodesktop -r "run('testing.m'); exit;"

When executed from a shell script, nothing happens until the timeout and kill option is reached. Also,

matlab -nodisplay -nosplash -nodesktop -r "run('testing.m'); exit;"

Runs without problems in a shell script.

Per comment above, adding the --foreground address the problem.

Most likely, The 'testing.m' need access to TTY/TTY signals. By default, the timeout will run the command as a child process, w

timeout --foreground --kill-after=10 25 matlab -nodisplay -nosplash -nodesktop -r "run('testing.m'); exit;"

From the timeout man page: --foreground when not running timeout directly from a shell prompt, allow COMMAND to read from the TTY and get TTY signals; in this mode, children of COMMAND will not be timed out --foreground when not running timeout directly from a shell prompt, allow COMMAND to read from the TTY and get TTY signals; in this mode, children of COMMAND will not be timed out

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM