Batch Executing SWI-Prolog Program


This question does not relate to coding in Prolog; I am rather asking for directions on how to solve a little annoying issue that is costing me a lot of testing effort.

In a nutshell, I am testing my program for a large set of input problems. My testing script is as simple as this Windows batch file:
swipl -l path/ -g goal1 -g halt
swipl -l path/ -g goal2 -g halt
swipl -l path/ -g goal341 -g halt

Then I will simply run this script in the good-old CMD console. The problem I am getting is that most of the time (in approximately 4 out of 5 runs) the script stops arbitrarily in the middle. When I consult the task manager I see something like this:

Looks like swipl finished but it is kind of hanging there.

My solution is to select “swipl” and end the task. This will immediately start the next line in the testing script, and testing resumes. At this point, the script might finish or might hang again (one or more times).

Eventually, after nudging the script whenever it feels like taking a nap, I can finally get my testing done. Each invocation of swipl in the script produces the intended results i.e. when the script hangs, it is doing so after solving the problem given to it.

The total execution time of swipl to solve the given problems is almost 3 hours, and so far I am unable to run it unattended.

I am trying to figure out why the script hangs at certain random points. Is this a SWI-Prolog issue or a Windows issue?

Any suggestions are appreciated.

I am using Windows 10 with SWI-Prolog developer version 8.1.19.

Many Thanks.

Hard to tell. I would use -t halt rather than -g halt. That might trap some (error) cases where it tries to start the toplevel. Not sure it really makes a difference though. Currently the command line processing is designed for batch processing using

swipl -g goal1 -g goal2 ... -t halt ...

The interesting questions is of course what is it doing? On a Linux system I’d say run gdb swipl <pid> and get a backtrace or even simpler, run kill -SEGV <pid> to force a crash and let the system dump a backtrace. Something like that might be doable using Windows tools, but I’m not good at Windows … Maybe someone else knows.

What happens if you type Control-C in the dos box?

Of course, you should also be able to do the job entirely in Prolog. Just load the programs into different modules and they shouldn’t hurt each other.

1 Like

I can’t say whether it is a Prolog or Windows issue, but with Windows

  1. Check Windows Event Viewer
  2. In extreme cases consider Sysinternals Utilities, in particular Process Monitor.