Sunday, September 22, 2024

Re: Need some information about fork(2)

So if I understand well, if a fork(2) come with execve(2) it freed automatically the resources. However if fork(2) come with any allocator, I should take care of it ?

On 2024-09-22T17:42:28.000+02:00, Otto Moerbeek <otto@drijf.net> wrote:
On Sun, Sep 22, 2024 at 05:33:36PM +0200, bilal@iscarioth.org wrote:

Sorry for disturbing you, again...

Does it means we should also free virtual memory from the child
process before exiting ?

All resources used by a process are freed automatically when the
process ends. Typically, a fork in the child is followed by an
execve(2) call, which replaces the current process by a new one, whith
only a few things inherited.

-Otto


On 2024-09-22T10:27:56.000+02:00, Otto Moerbeek <otto@drijf.net>
wrote:

On Sun, Sep 22, 2024 at 10:08:56AM +0200, bilal@iscarioth.org wrote:

Hello OpenBSD team

I'm having a little trouble understanding how this works.

of fork(2), according to man. It's an exact copy of the parent

process.

There are limitations that are explicit in the man. However,

I wanted to know if the pointers we use are the same.

For example, if I had allocated 4 bytes in my parent process, I
would

launch the fork...

If I release this address from the child, is the father's pointer

still intact, or is it released?

Translated with DeepL.com [http://DeepL.com] (free version)

It's an exact copy, all memory allocations remain the same. The
trick

is the new process virtual memory space is seperate, so the equal

pointer actually refer to different sets of memory (each process has

it's onwn virual memory space). So an allocatoon or free done by the

parent or child does not interfere with the other process.

-Otto


No comments:

Post a Comment