What is inherited by a child process?

Jim picture Jim · Oct 9, 2012 · Viewed 7.6k times · Source

Does a forked process inherit any (server) ports bind from the parent process?
I have a java process which forks a child process and from netstat -anpt |grep I see that both parent and child are bound to the same port.
Is this possible? Is there a way to get arround this?

Answer

Peter Lawrey picture Peter Lawrey · Oct 9, 2012

Does a forked process inherit any (server) ports bind from the parent process?

Its inherits the resources of its parent. This is the way the OS behaves.

Is there a way to get around this?

The child has to close all the resources it doesn't need. This is relatively easy to do in C but not simple in Java. There might be a way to start a Java process with clean set of resources, but I don't know of a way to do this.