:: Re: [DNG] Mini init script written …
Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: Steve Litt
Ημερομηνία:  
Προς: dng
Αντικείμενο: Re: [DNG] Mini init script written in Perl boots.
On Fri, 17 Jun 2016 04:43:28 +0300
Lars Noodén <lars.nooden@???> wrote:

> On 06/16/2016 11:01 PM, Edward Bartolo wrote:
> [snip]
> > if (fork()) {
> > # We are in the parent which must reap zombies.
> >   while(1) {
> >       $status = wait();
> >     }    
> > } else {
> > # We are in the child which must load the operating system by
> > executing a script

> >
> > exec("/sbin/osloader.sh");
> > }
>
> Thanks very much for this demo. I see that on devuan jessie what I
> have is ps showing 22 processes with a PPID of 1. So, when you say
> that this perl script is minimal, do you mean that it would contain
> other fork actions if it is to more closely emulate package
> sysvinit-core's /sbin/init ? And that that those forks (new
> processes), through a chain of scripts or programs that use exec, end
> up as various daemons and such?
>
> Regards,
> Lars


My understanding is as follows:

Edward's pid1 shellscript has exactly one child, /sbin/osloader.sh.
That child can fork off a whole lot more processes. So theoretically,
with Edward's PID1 instead of sysvinit, only one process would have a
PPID of 1, that being /sbin/osloader.sh.

BUT...

Processes can be doubleforked, which puts them in the background with
PID1 as their parent. This allows them to be run by processes that
later close, without using nohup. So every doubleforked program would
have a PPID of 1.

For instance, gvim doubleforks itself, so that it can survive after the
terminal upon which it was launched is closed. Look in ps axjf, and
you'll see every gvim has a PPID of 1.

My Void box inits with runit, which is very close to what Edward is
building. Theoretically everything would be spawned from PID2, the rc
file. But nooooooo! Besides the doubleforked stuff, all the dbus
related stuff has a PPID of 1. udevd -daemon likewise has PPID1, as
does the background process for runit's process supervisor, runsvdir.


SteveT

Steve Litt
June 2016 featured book: Troubleshooting: Why Bother?
http://www.troubleshooters.com/twb