comp.lang.ada
 help / color / mirror / Atom feed
From: "Warren W. Gay VE3WWG" <ve3wwg@cogeco.ca>
Subject: Re: stupid question: how can I finish a program?
Date: Thu, 29 Aug 2002 12:49:02 -0400
Date: 2002-08-29T12:49:02-04:00	[thread overview]
Message-ID: <3D6E507E.7010805@cogeco.ca> (raw)
In-Reply-To: wccit1utvz4.fsf@shell01.TheWorld.com

Robert A Duff wrote:
> Darren New <dnew@san.rr.com> writes:
>>Robert A Duff wrote:
>>>Darren New <dnew@san.rr.com> writes:
>>>>Robert A Duff wrote:
>>>>
>>>>>If you're running under a proper operating system, then all resources
>>>>>visible outside the program will be cleaned up when the program exits.
>>>>
>>>>This is true only in the most trivial sense. If I have a program that
>>>>contacts a license manager (for example) and grabs the license, then aborts,
>>>>I could be in trouble. That's why license managers check for that sort of
>>>>failure.
>>>
>>>So if it's checked for, what's the problem?
>>
>>Well, it isn't the OS doing it.
> 
> OK, I admit, I was oversimplifying.
> 
> Still, if the OS allocates some physical memory to a process, and the
> process dies, the OS ought to reclaim that memory.  If a license manager
> allocates a license to a process, and the process dies, the license
> manager ought to reclaim it.  ...

Even in "proper O/S" there are occaisions where cleanup is needed,
but not automatically done by the O/S. Here are 3 examples of
this, that can happen on [pick your] UNIX:

   - Allocated _SHARED_ memory
   - Created message queues (IPC)
   - Create semaphores

The reason these are not automatically cleaned up by the O/S is that
sometimes you want them to persist beyond the creating process'
lifetime (because they are shared by other processes).

However, you may also not want those resources to exist upon the
process termination -- this depends upon the application, or process
involved.

> My point is simply that "exit" shouldn't be any worse than a crash.

It can be, just see the above. It can leave unwanted IPC resources
hanging around, and even worse, in an indeterminant state (for shared
memory region could be left partially updated).

Also, if exit is called with threads (tasks) involved, and this
is invoked in an uncoordinated way, the "cleanup code" itself
can barf all over the place leading to things like high CPU usage
loops (hanging process), core file or spewing output etc., because
now you are expecting cleanup code to cleanup with "indefined state"
data.

> And that we can't rely on Ada finalization for those sorts of cleanup.

Especially in the context of "safe programming" practices.

>>I think it more depends on what you mean by "resources". I've worked on OSes
>>where you had "temp files" that went away when you logged out. UNIX doesn't
>>have that. Are junk-files in /tmp a "resource leak" the OS should clean up?
> 
> I don't know.  I suppose Unix is broken in that regard.  I must admit
> that I've had to delete "by hand" some junk in /tmp, which rogue
> programs left lying around.
> 
> - Bob

This depends upon the application designer (not the O/S). The temp file
is indeed automatically cleaned up by the O/S if the application writer
uses the correct calls or does it correctly himself. If you truly want
the file to cleanup itself, open(2) it, unlink(2) it, and the file will
automatically be cleaned up when the file is close(2) (voluntarily
by the application or by the O/S when the process is terminated, even
in the kill -9 or abort case).

The point is that the O/S is not broken in this regard ;-)

Many people rely on the atexit() processing, which is like
finalization -- you cannot always count on it in an abort-like
termination of the program (definitely not, when kill -9 is
involved). But don't blame the O/S for this. This type of
cleanup is voluntary application cleanup -- only that the
app usually depends upon library routines to do it.

-- 
Warren W. Gay VE3WWG
http://home.cogeco.ca/~ve3wwg




  reply	other threads:[~2002-08-29 16:49 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <c923f575.0208130627.479e0b3d@posting.google.com>
2002-08-13 14:37 ` stupid question: how can I finish a program? chris.danx
2002-08-13 23:53   ` Robert C. Leif
2002-08-14  2:07     ` Wes Groleau
2002-08-14  5:53       ` Robert C. Leif
2002-08-14 13:30         ` Wes Groleau
2002-08-14 13:56       ` Marin D. Condic
2002-08-17 15:58         ` Robert Dewar
2002-08-14 19:18       ` Simon Wright
2002-08-15 14:02         ` Wes Groleau
2002-08-15  1:47       ` Robert Dewar
2002-08-15  5:14         ` Michael Bode
2002-08-17 14:28           ` Alfred Hilscher
2002-08-15  5:17         ` tmoran
2002-08-15 18:41           ` Robert Dewar
2002-08-14 13:53     ` Marin D. Condic
2002-08-15 17:39       ` tmoran
2002-08-16 13:46         ` Marin D. Condic
2002-08-17 14:26           ` Warren W. Gay VE3WWG
2002-08-22 19:16           ` tmoran
2002-08-22 20:54             ` Marin D. Condic
2002-08-25  2:22       ` Robert Dewar
2002-08-26 15:59         ` Marin D. Condic
2002-08-27 21:59         ` Robert A Duff
2002-08-28 20:40           ` Dmitry A.Kazakov
2002-08-28 13:59             ` Robert A Duff
2002-08-28 16:55               ` Darren New
2002-08-28 18:36                 ` Larry Kilgallen
2002-08-28 22:22                 ` Robert A Duff
2002-08-28 22:30                   ` Darren New
2002-08-28 23:16                     ` Robert A Duff
2002-08-29 16:49                       ` Warren W. Gay VE3WWG [this message]
2002-08-29 18:55                         ` Larry Kilgallen
2002-08-29 19:17                           ` Warren W. Gay VE3WWG
2002-08-30  8:09                         ` Ole-Hjalmar Kristensen
2002-08-31 20:39                           ` Warren W. Gay VE3WWG
2002-08-29 16:35                   ` Dennis Lee Bieber
2002-08-29 22:48               ` Dmitry A.Kazakov
2002-08-29 15:18                 ` Robert A Duff
2002-08-30  4:29                   ` Dmitry A.Kazakov
2002-08-29 16:53                     ` Warren W. Gay VE3WWG
2002-08-29 19:03                     ` Robert C. Leif
2002-08-29 19:25                       ` Warren W. Gay VE3WWG
2002-08-29 20:42                       ` Larry Kilgallen
2002-08-29 20:22                         ` Robert A Duff
2002-08-30 20:59                           ` Simon Wright
2002-08-28 14:33             ` Marin D. Condic
2002-08-28 22:15               ` Larry Kilgallen
2002-08-29 15:30                 ` Robert A Duff
2002-08-29 22:16               ` Dmitry A.Kazakov
2002-08-29 13:17                 ` Marin D. Condic
2002-08-29 19:32                   ` Robert A Duff
2002-08-31  2:40                   ` Dmitry A.Kazakov
2002-08-31  0:10                     ` Toshitaka Kumano
2002-09-02 21:02                       ` Dmitry A.Kazakov
2002-08-29 16:59                 ` Warren W. Gay VE3WWG
2002-08-29 18:26                   ` Marin D. Condic
2002-08-13 14:38 ` David C. Hoos
2002-08-13 20:08   ` Adam Beneschan
2002-08-14  6:41 ` Emil Moholth
2002-08-14 14:00   ` Marin D. Condic
2002-08-14  7:37 ` Martin Dowie
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox