4

I start a new process from GNOME Terminal and then this process fork a child. But when I killed the parent process the orphaned process's parent id became something other than 1 which represent init --user pid.
When I do this in virtual terminals, the parent pid is 1 which represent init process.
How can I execute new process from GNOME Terminal so that when it is died, the child process's parent pid became 1 and not pid of init --user process?
Thanks a lot.

  • 1
    why have you edit the title and question? to this crap? – demonking Apr 3 '15 at 20:01
  • 2
    Please do not vandalize. If you really must delete, go for it, but there's a very good answer here, and it would be to no one's benefit. – mikeserv Apr 3 '15 at 20:26
  • @mikeserv But how I can delete it? – user2142353456 Apr 4 '15 at 3:11
  • Oh no - you won't get that answer out of me (though, honestly, I only assume you can anway). I will say, though, that if you did a little more legwork for yourself you might find yourself less likely to ask embarrassing questions. Still - you should be pleased - the answer here is excellent, and offered by someone who has been frequently doing it very well for many years. My two cents - if you really want to avoid the the user session namespace so badly, then just don't launch it. Or else go the other way - and start your own PID 1. – mikeserv Apr 4 '15 at 8:41
9

I already answered a similar question a few months ago. So see that first for technical details. Here, I shall just show you how your situation is covered by that answer.

As I explained, I and other writers of various dæmon supervision utilities take advantage of how Linux now works, and what you are seeing is that very thing in action, almost exactly as I laid it out.

The only missing piece of information is that init --user is your session instance of upstart. It is started up when you first log in to a session, and stopped when you log out. It's there for you to have per-session jobs (similar, but not identical, to MacOS 10's user agents under launchd) of your own.

A couple of years ago, the Ubuntu people went about converting graphical desktop systems to employ upstart per-session jobs. Your GNOME Terminal is being started as a per-session job, and any orphaned children are inherited by the nearest sub-reaper, which is of course your per-session instance of upstart.

The systemd people have been, in recent months, working on the exact same thing, setting up GNOME Terminal to run individual tabs as separate systemd services, from one's per-user instance of systemd. (You can tell that your question is about upstart, not systemd, because on a systemd system the sub-reaper process would be systemd --user.)

How can I execute a new process from GNOME Terminal so that the child process's parent PID becomes 1 and not the PID of the ubuntu session init process?

This is intentionally hard. Service managers want to keep track of orphaned child processes. They want not to lose them to process #1. So the quick précis is: Stop trying to do that.

If you are asking solely because you think that your process ought to have a parent process ID of 1, then wean yourself off this idea.

If you erroneously think that this is an aspect of being a dæmon, then note that dæmons having parent process IDs of 1 has not been guaranteed (and on some Unices, not true across the whole system) since the advent of things like IBM's System Resource Controller and Bernstein's daemontools in the 1990s. In any case, one doesn't get to be a dæmon by double-forking within a login session. That's a long-since known to be half-baked idea.

If you erroneously think that this is a truism for orphaned child processes, then read my previous answer again. The absolutism that orphaned children are re-parented to process #1 is wrong, and has been wrong for over three years, at the time of writing this.

If you have a child process that for some bizarre reason truly needs this, then find out what that bizarre reason is and get it fixed. It's probably a bug, or someone making invalid design assumptions. Whatever the reason, the world of dæmon management changed in the 1990s, and Linux also changed some several years ago. It is time to catch up.

Further reading

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.