LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-05-2009, 11:07 PM   #1
venkat_k
Member
 
Registered: Sep 2008
Posts: 36

Rep: Reputation: 15
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?
 
Old 04-06-2009, 01:37 AM   #2
sieira
Member
 
Registered: Dec 2007
Location: Alcalá de Henares (Madrid)
Distribution: Debian
Posts: 40

Rep: Reputation: 16
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.
 
Old 04-07-2009, 03:47 PM   #3
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 47
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
 
Old 04-07-2009, 10:24 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,636
Blog Entries: 4

Rep: Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933
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.)
 
Old 04-11-2009, 05:58 PM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
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.
 
Old 04-11-2009, 06:47 PM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
IPC fails between user process and root process zaryab Linux - Newbie 1 09-22-2008 01:25 AM
How to remove defunct process without reboot and without "kill -9 ppid()" ? murugesan Linux - Software 2 07-17-2008 05:54 AM
Start a program for a user as root, with process belonging to user gnashley Programming 4 03-19-2007 01:58 PM
how to make ppid of a process as init without killing its parent shantha Programming 10 12-17-2004 07:36 AM
pidof -o %PPID program vanalex Linux - General 2 01-26-2004 09:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration