From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,a6414d7d26b803ce X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!p10g2000prm.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Ada and (SIGTERM?) Date: Wed, 5 Aug 2009 18:06:22 -0700 (PDT) Organization: http://groups.google.com Message-ID: <4244cbe7-1655-484b-a376-0237802ab37d@p10g2000prm.googlegroups.com> References: <42c9446c-76d2-4c82-abab-fd7c5573d85e@k30g2000yqf.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1249520782 15784 127.0.0.1 (6 Aug 2009 01:06:22 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 6 Aug 2009 01:06:22 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p10g2000prm.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:7618 Date: 2009-08-05T18:06:22-07:00 List-Id: On Aug 5, 12:58=A0pm, Tomek Walkuski wrote: > Consider program with infinite loop, it simply acts as a server. > > How to kill it gracefully with housekeeping (finalization etc)? I suppose "gracefully" precludes pulling the computer's plug out of the wall? If I understand, by the subject line, that this program is running on some Unix-like system and you'd like the program to respond to a signal and terminate gracefully: did you look at RM C.3? It seems to me you could set up an interrupt handler to catch SIGTERM and have it set a global Boolean variable (make sure to use the Volatile pragma on the variable), then instead of an "infinite" loop, make the loop "while not Terminate loop" ... where Terminate is the global variable that gets set by the interrupt handler. The details depend on your Ada implementation. But that's one simple way to accomplish it. No doubt there are other ways, and probably better ones (e.g. the interrupt handler, which must be a procedure in a protected object, could set a Boolean in the protected object that controls a protected entry in the object that could be used in a "select" statement, or something like that). In any case, C.3 is the place to start. -- Adam