asynntrp.gms : Start GAMS job asynchronously and send interrupt signal to it

Description

'$Call.ASyncNC' starts a job in a new, minimized console. With 'JobHandle' one
gets the process ID of that job and the put_utility 'WinMsg' sends an interrupt
signal to that PID. On Unix we get the list of PIDs using the utility pstree and
send a interrupt signal to these processes.

Contributor: Lutz Westermann


Small Model of Type : GAMS


Category : GAMS Test library


Main file : asynntrp.gms

$Title  Start GAMS job asynchronously and send interrupt signal to it (ASYNNTRP,SEQ=585)

$ontext
'$Call.ASyncNC' starts a job in a new, minimized console. With 'JobHandle' one
gets the process ID of that job and the put_utility 'WinMsg' sends an interrupt
signal to that PID. On Unix we get the list of PIDs using the utility pstree and
send a interrupt signal to these processes.

Contributor: Lutz Westermann
$offtext

$ifthen %system.filesys% == UNIX
$call which pstree > /dev/null 2>&1 
$if errorlevel 1 $abort.noerror Under Unix we require the pstree utility
$set sedcmd
$set pstree pstree -p
$if LEX==%system.platform% $set sedcmd sed 's/(/\n(/g' | grep '(' | sed 's/(\(.*\)).*/\1/'
$ifthen.DEX DEX==%system.platform%
$  set sedcmd sed 's/^.*- /(/g' | grep '^(' | cut -f 1 -d ' ' | sed 's/(//g'
$  set pstree pstree pid
$endif.DEX
$if "x%sedcmd%"==x
$abort.noerror pstree output requires stream editing. Please specify command to extract a list of pids
$endif

$call gamslib -q cube
$onecho > cubex.gms
$set nosolve 1
$include cube.gms
Solve cube minimizing num using mip;
scalar sstat; sstat = cube.solvestat;
$offecho

$Call.ASyncNC =gams cubex mip=bdmlp gdx=cubeout lo=2
$eval jh JobHandle

file fx;
display$sleep(0.5) 'wait';
$ifthen %system.filesys% == UNIX
put_utility fx 'shell' / "%pstree% %jh% | %sedcmd% | xargs kill -2 > /dev/null 2>&1"
$else
put_utility fx 'winmsg' / '___GAMSMSGWINDOW___%jh%' / "GAMS Message Interrupt";
$endif
display$sleep(1) 'wait';

scalar sstat; execute_load 'cubeout' sstat;
abort$(sstat<>%Solvestat.User Interrupt%) 'Wrong status code', sstat;