When a program crashes, is its memory reclaimed by the OS?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > When a program crashes, is its memory reclaimed by the OS?




Pages (2): [1] 2 »   Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    When a program crashes, is its memory reclaimed by the OS?  
D'artagnan


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-23-06 06:17 AM

Dynamically allocated (malloc) memory is returned back to the OS when a
program terminates normally. But what if the program crashes? Is its
heap also freed? Thanks.






[ Post a follow-up to this message ]



    Re: When a program crashes, is its memory reclaimed by the OS?  
Erik Max Francis


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-23-06 06:17 AM

D'artagnan wrote:

> Dynamically allocated (malloc) memory is returned back to the OS when a
> program terminates normally. But what if the program crashes? Is its
> heap also freed? Thanks.

Yes.

--
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
To attempt to defend everything is to defend nothing.
-- Frederick the Great





[ Post a follow-up to this message ]



    Re: When a program crashes, is its memory reclaimed by the OS?  
Paul Pluzhnikov


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-23-06 06:17 AM

"D'artagnan" <musketeers@gmail.com> writes:

> Dynamically allocated (malloc) memory is returned back to the OS when a
> program terminates normally. But what if the program crashes? Is its
> heap also freed?

The heap is not freed in the sense of free(3).

It simply disappears when the OS reclaims all resources allocated
to the process, and this reclamation happens regardless of whether
the process exited (normally of with an error), was killed by signal,
or exec()ed another program.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.





[ Post a follow-up to this message ]



    Re: When a program crashes, is its memory reclaimed by the OS?  
Russell Shaw


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-23-06 06:17 AM

Paul Pluzhnikov wrote:
> "D'artagnan" <musketeers@gmail.com> writes:
> 
>
> The heap is not freed in the sense of free(3).
>
> It simply disappears when the OS reclaims all resources allocated
> to the process, and this reclamation happens regardless of whether
> the process exited (normally of with an error), was killed by signal,
> or exec()ed another program.

It only works on systems with a hardware memory manager that keeps
track of the memory allocated to a process. On old DOS systems without
a MMU, a bad program will crash the system.





[ Post a follow-up to this message ]



    Re: When a program crashes, is its memory reclaimed by the OS?  
Frank Cusack


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-23-06 06:17 AM

On Tue, 23 May 2006 15:02:37 +1000 Russell Shaw <rjshawN_o@s_pam.netspace.net.au> wrote:[vbc
ol=seagreen]
> Paul Pluzhnikov wrote: 
>
> It only works on systems with a hardware memory manager that keeps
> track of the memory allocated to a process. On old DOS systems without
> a MMU, a bad program will crash the system.[/vbcol]

Well, this is comp.*unix*.programmer. :-)  Is there any Unix (or unix)
that doesn't reclaim memory?  Certainly even today there are unix systems
that run on hardware without an MMU.

-frank





[ Post a follow-up to this message ]



    Re: When a program crashes, is its memory reclaimed by the OS?  
Hubble


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-23-06 06:17 AM

>It only works on systems with a hardware memory manager that keeps
>track of the memory allocated to a process. On old DOS systems without
>a MMU, a bad program will crash the system.

It also works on Unix(-like) systems without an MMU, e.g. MINIX on 8086
(version1 and version2)

On most systems it works like this (even without MMU)

* A process has three segments
* TEXT for the program code (unchangable)
* DATA for initialized data
* BSS for uninitalized data

On start from an elf or a.out file, these segments are allocated as
needed.

The BSS segment can be growed and shrinked by the sbrk(2) system call.
Library functions like malloc use this call if they need more memory.
Some implementations never shrink the BSS (free keeps a list of
previously allocated memory, subsequent mallocs first consider if
memory in this list can be used, otherwise allocate a big chunk of
additional BSS space)

The OS keeps track of the segments. If a program exits or crashes, it
knows exactly the place and size of these segments and reclaims this
memory.

Hubble.






[ Post a follow-up to this message ]



    Re: When a program crashes, is its memory reclaimed by the OS?  
Maxim Yegorushkin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-23-06 12:16 PM


D'artagnan wrote:
> Dynamically allocated (malloc) memory is returned back to the OS when a
> program terminates normally. But what if the program crashes? Is its
> heap also freed? Thanks.

Adding to what others have said, shared memory has kernel persistence.
This means it has to be explicitly unlink()ed and the OS never does
that for you. The same applies for message queues and semaphores.

http://www.opengroup.org/onlinepubs...shm_unlink.html
http://www.opengroup.org/onlinepubs.../mq_unlink.html
http://www.opengroup.org/onlinepubs...sem_unlink.html






[ Post a follow-up to this message ]



    Re: When a program crashes, is its memory reclaimed by the OS?  
Alex Colvin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-23-06 06:17 PM

>>>Dynamically allocated (malloc) memory is returned back to the OS when a 
[vbcol=seagreen]
>It only works on systems with a hardware memory manager that keeps
>track of the memory allocated to a process. On old DOS systems without
>a MMU, a bad program will crash the system.

more like
It only works on an operating system, not on a program loader like DOS.

--
mac the naïf





[ Post a follow-up to this message ]



    Re: When a program crashes, is its memory reclaimed by the OS?  
anu


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-24-06 06:20 AM

Hello Paul

How will we know that memory is free or not ? is there any procedure
to see the freed memory and allocated memory ?

bye

anagha


Paul Pluzhnikov wrote:
> "D'artagnan" <musketeers@gmail.com> writes:
> 
>
> The heap is not freed in the sense of free(3).
>
> It simply disappears when the OS reclaims all resources allocated
> to the process, and this reclamation happens regardless of whether
> the process exited (normally of with an error), was killed by signal,
> or exec()ed another program.
>
> Cheers,
> --
> In order to understand recursion you must first understand recursion.
> Remove /-nsp/ for email.






[ Post a follow-up to this message ]



    Re: When a program crashes, is its memory reclaimed by the OS?  
sandy


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-24-06 12:16 PM


D'artagnan wrote:

> Dynamically allocated (malloc) memory is returned back to the OS when a
> program terminates normally. But what if the program crashes? Is its
> heap also freed? Thanks.

Google about " grabage collectors ". Its actually freed when the
garbage collector is executed.

Cheers,
Sandeepksinha.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 10:48 AM.      Post New Thread    Post A Reply      
Pages (2): [1] 2 »   Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register