Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a child process generated by "fork()" ever have a process id lesser than its parent?

Can a child process generated by fork() ever have a process id lesser than its parent(without crossing the maximum limit)?

The PID is usually the next available value but anyhow can it possibly be less than the parent's PID?

like image 297
Imdad Avatar asked Feb 07 '14 19:02

Imdad


People also ask

What happens when a child process is forked?

Fork system call is used for creating a new process, which is called child process, which runs concurrently with the process that makes the fork() call (parent process). After a new child process is created, both processes will execute the next instruction following the fork() system call.

Does child have the same PID as parent?

The child process has a unique process ID (PID) that does not match any active process group ID. The child has a different parent process IDparent process IDIn computing, a parent process is a process that has created one or more child processes.https://en.wikipedia.org › wiki › Parent_processParent process - Wikipedia, that is, the process ID of the process that called fork(). The child has its own copy of the parent's file descriptors.

What does the fork () return to the child process?

Upon successful completion, fork() returns 0 to the child process and returns the process ID of the child process to the parent processparent processIn computing, a parent process is a process that has created one or more child processes.https://en.wikipedia.org › wiki › Parent_processParent process - Wikipedia. Otherwise, -1 is returned to the parent process, no child process is created, and errno is set to indicate the error.

What are the differences between a parent process and its forked child process?

Some differences between the child and parent process are:different pids. in the parent, fork( ) returns the pid of the child process if a child process is created. in the child, fork( ) always returns 0. separate copies of all data, including variables with their current values and the stack.


2 Answers

Yes. PIDs are not guaranteed to be in any order. Some systems and some security extensions generate random PIDs to avoid attacks based on child PID prediction. Of course even systems that linearly generate PIDs need to wrap around at some point.

like image 198
Variable Length Coder Avatar answered Sep 29 '22 16:09

Variable Length Coder


Yes. PIDs are reused, and on some systems, PIDs do not necessarily increase monotonically.

like image 40
Greg Bacon Avatar answered Sep 29 '22 17:09

Greg Bacon