Linux – What properties of an unprivileged process are preserved during an `execve` call

capabilitiesexeclinuxprocess

I am teaching an Operating Systems course and trying to wrap my mind around the fork/execve technique for creating new processes.

My current understanding is that a fork make a complete copy of the old process, establishes a new PID and parent/child relationship, but otherwise does very little else.

On the other hand, after the child process is created, it runs execve to replace most of its memory with the new process. For example, the program code, stack, and heap are completely replaced and started from scratch as a new program.

But not everything is replaced in the new process. The child process inherits file descriptors (which allows pipes to be set up before the execve), the process ID (PID) and user ID (UID) and some permissions (man page).

I imagine the full list of properties that are NOT replaced by an execve call is quite long, but are there any other key properties like the ones I mentioned above that I'm missing?

Best Answer

Since we’re discussing Linux specifically (at least, I take it that’s what you want since you used the tag), the fork and execve manpages are the appropriate references; they list all the attributes which aren’t preserved. Most of this behaviour is specified by POSIX, but there are some Linux specificities.

The man pages don’t list attributes which are preserved, focusing instead on those which aren’t:

All process attributes are preserved during an execve(), except the following:

etc.

I won’t try to answer your question by listing all the attributes which are preserved. However I will point out one key property which is preserved, and which you haven’t listed: ignored and default signals are preserved across execve. This means that a parent can ignore a signal (at least, signals that can be ignored) and that behaviour will be propagated to any children. This is what allows nohup to work.

You can find a complete list of process attributes, with an explanation of what happens to them on exec() or fork(), in section 28.4 of The Linux Programming Interface.