From jan@swi.psy.uva.nl Tue Jun 19 10:32:15 2001 Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30]) by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f5J8WFc07656; Tue, 19 Jun 2001 10:32:15 +0200 (MET DST) Received: from localhost (localhost [[UNIX: localhost]]) by gollem.swi.psy.uva.nl (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) id f5J8WA209524; Tue, 19 Jun 2001 10:32:10 +0200 From: Jan Wielemaker Organization: SWI, University of Amsterdam To: "Andrew V. Diatchkov" , prolog@swi.psy.uva.nl Subject: Re: [SWIPL] on_signal Date: Tue, 19 Jun 2001 10:20:52 +0200 X-Mailer: KMail [version 1.0.29.2] Content-Type: text/plain References: In-Reply-To: MIME-Version: 1.0 Message-Id: <01061910321000.06418@gollem> Content-Transfer-Encoding: 8bit Andrew, On Tue, 19 Jun 2001, Andrew V. Diatchkov wrote: >Hello. >I'm using on_signal for handling SEGV signal and halt my >program in this case (SWI-Prolog 4.0.7, RedHat Linux 7.1). > >There is the test program (see below) which doesn't handles SIGSEGV. I >would like to use it as runtime application. Can you help? For two reasons. First of all, you make a saved-state, but signal handling state isn't part of the state, so you need :- initialization on_signal(segv, _, sigsegv). Next, SEGV is used internally for stack-guarding on many Unix systems, including Linux. This means that, after receiving a SIGSEGV it checks whether there are any stacks `low'. If so it expands them and returns. If there is no stack low it behaves as with any other signal, checking the on_signal declaration and then mapping the signal onto a foreign routine, Prolog exception or Prolog routine. >main.pl : > >:- on_signal(segv,_,sigsegv). > >sigsegv(Context) :- writef('Done. Context=%w',[Context]),nl,halt. >main :- > repeat, > sleep(1.0), > fail. > >Makefile : >prog: main.pl > pl -o prog -t >'[main],qsave_program(prog,[goal=true,toplevel=main,stand_alone=true])' P.s. This gives the same result and looks a bit prettier in your Makefile: pl -o prog --toplevel=main --stand_alone=true --goal=true -c main.pl These days I normally use the #! script alternative. Unless your program is huge it works quick and easy. #!/usr/bin/pl -g true -t main -q -s