From owner-freebsd-questions Mon Mar 22 13:38:33 1999 Delivered-To: freebsd-questions@freebsd.org Received: from alpha.comkey.com.au (alpha.comkey.com.au [203.9.152.215]) by hub.freebsd.org (Postfix) with SMTP id 2D34E14EF4 for ; Mon, 22 Mar 1999 13:38:24 -0800 (PST) (envelope-from gjb@comkey.com.au) Received: (qmail 9970 invoked by uid 1001); 22 Mar 1999 21:32:50 -0000 Message-ID: <19990322213250.9969.qmail@alpha.comkey.com.au> X-Posted-By: GBA-Post 1.04 06-Feb-1999 X-PGP-Fingerprint: 5A91 6942 8CEA 9DAB B95B C249 1CE1 493B 2B5A CE30 Date: Tue, 23 Mar 1999 07:32:50 +1000 From: Greg Black To: Karl Pielorz Cc: Masahiro Ariga , freebsd-questions@FreeBSD.ORG Subject: Re: how to die gracefully References: <000501be7472$3bbeb400$064ca8c0@gateway> <36F65B11.610DAE9D@tdx.co.uk> In-reply-to: <36F65B11.610DAE9D@tdx.co.uk> of Mon, 22 Mar 1999 15:00:33 GMT Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > First loaded program works fine,and enters Ctl^C to exit it,but if I execute > > it second time,it shows abnormalties like taking time to start to send data > > to clent,and badly enough,it responds not at all. > > I presume it results from not closing sockets,or residual memory or > > something,but I'm not sure. > > AFAIK - when your program quit's, the O/S should free up it's memory and close > it's files etc. (as a kind of last-resort) - it's probably not good practice > to rely on this though, especially if your program is designed to run for long > periods of time... This is wrong. The OS reclaims everything when the program exits. > > So,sinior UNIX programers,would you teach me next two questions ? > > > > 1.How should I exit gracefully by pushing Ctl^C. I mean,what should I do to > > recover normal condition in preparation for next execution ? > > Catch the CTRL-C signal, then perform housekeeping & cleanup (i.e. close > files, sockets, freeup memory used etc. - all of which your program should > have tracked etc.), then quit... This begs the question. If it's a client/server interaction, then the issues are probably to do with leaving one end of the connection waiting when the other quits. There's not enough information here to help, and it's not a topic for this list anyway. Get one of the books on client/server programming under BSD (I'd suggest Stevens), study it, find a suitable source of help if you need it, read BSD sources for inspiration, and keep working on it. > > 2.I like to catch the signal when pushed Ctl^C,and make a handler > > routine.Would you tell me what signal I can catch when enterring Ctl^C ? > > SIGQUIT I think - check the man pages out (man signal)... Wrong. It's SIGINT. The QUIT signal is usually attached to Ctl-\ and generates a core dump as well as interrupting the process. -- Greg Black To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message