LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   why is the ppid is 1 for a user process? (https://www.linuxquestions.org/questions/programming-9/why-is-the-ppid-is-1-for-a-user-process-717077/)

venkat_k 04-05-2009 11:07 PM

why is the ppid is 1 for a user process?
 
I have an application which runs few processes.
"ps" output of one of the processes shows the PPID of a process is 1.
what it exactly it means?

sieira 04-06-2009 01:37 AM

The "init" process always takes PID 1, when a process dies, it's child processes are inherited by him. Generally, init only starts system processes

A user process having 1 as PPID means probably that this process was created as a user-space one, and after that, it's father died.

jan61 04-07-2009 03:47 PM

Moin,

you can yourself create such processes using "nohup program &". They will run at the background and don't terminate, when you exit the shell.

Jan

sundialsvcs 04-07-2009 10:24 PM

One of the fundamental design-points of Linux or Unix is that many things are done by "spawning child processes" to do things, then waiting for them to finish and examining the return-code they provide. For this reason, when a process dies, it enters a "zombie" state that specifically exists so that the parent-process can "reap" the now-dead child and, in so doing, collect its status information.

"But what if the parent dies first?"

Generally, but not always, the death of a parent causes the death of all of its direct or indirect children. But in any case, when any process dies, some "parent process" must "reap" it.

If there is no "true" parent-process available, "process #1: init" gets to serve as the Grim Reaper, among its various other duties.

"init" is a very special process: it is created by the system during startup, and it never dies. (It is not allowed to die... a "kernel panic" will occur if it ever does.)

bigearsbilly 04-11-2009 05:58 PM

when a process is created it's typically from a user's shell, the shell is the session leader.
and the parent. when you logout the shell all the kids die too.
they get a signal from the parent.

sometimes you want a process to be independent of the parent, like a daemon, so it doesn't
die when you log out.

so typically if you want this behaviour the program calls
fork
followed by
setsid
becoming a session leader and getting the PPID of 1 the 'init' process
which is the ultimate parent of all.
e.g. gvim does this.

paulsm4 04-11-2009 06:47 PM

venkat_k:

Just to clarify - jan61's response is probably closest to what you were actually looking for:

Quote:

You can yourself create such processes using "nohup program &"
The reason to use "nohup" is 1) you want to spawn a subprocess, but 2) you want to disassociate it from your login (in other words, you want the new process to continue, even after you log out).

'Hope that helps .. PSM


All times are GMT -5. The time now is 04:01 AM.