Thread Subject: Kill a process if it runs too long

Subject: Kill a process if it runs too long

From: Andreas

Date: 9 Feb, 2010 15:52:04

Message: 1 of 3

Hello all,

I'm calling some Fortran code from within a matlab loop, which usually takes ca. 10 seconds to run through per run. The whole program is set up like this:

nmc = 1e3;
while nrun < nmc
   nrun = nrun +1;
    !echo -e "orbitinp.tmp\n-100" | ./orbit
% Followed by lots of stuff to evaluate the output from ./orbit
end

Sometimes the "orbit" code freezes, though, so I would like to kill it from within matlab if that happens. Is there a way to set something like a process-time threshold so that I could say

%tic
!echo -e "orbitinp.tmp\n-100" | ./orbit &
if time > threshold
   continue
end

Thanks for any tip or alternative ideas.
Andreas

Subject: Kill a process if it runs too long

From: Steve Amphlett

Date: 9 Feb, 2010 16:40:22

Message: 2 of 3

"Andreas " <andreas.koch1@gmx-removethis.de> wrote in message <hks0b4$fl9$1@fred.mathworks.com>...
> Hello all,
>
> I'm calling some Fortran code from within a matlab loop, which usually takes ca. 10 seconds to run through per run. The whole program is set up like this:
>
> nmc = 1e3;
> while nrun < nmc
> nrun = nrun +1;
> !echo -e "orbitinp.tmp\n-100" | ./orbit
> % Followed by lots of stuff to evaluate the output from ./orbit
> end
>
> Sometimes the "orbit" code freezes, though, so I would like to kill it from within matlab if that happens. Is there a way to set something like a process-time threshold so that I could say
>
> %tic
> !echo -e "orbitinp.tmp\n-100" | ./orbit &
> if time > threshold
> continue
> end
>
> Thanks for any tip or alternative ideas.
> Andreas

Maybe overkill, but...

Have your process take a numerical argument. Pass that value to alarm() and have a signal trap ready for SIGALRM, which quits the process.

Subject: Kill a process if it runs too long

From: Jan Simon

Date: 10 Feb, 2010 22:02:03

Message: 3 of 3

Dear Andreas!

> Sometimes the "orbit" code freezes, ...

The easiest way would be to clean the code of "orbit", such that it don't freeze anymore...

Kind regards, Jan

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com