session leader different under qnxrtp?

I am trying to port my qnx4 app to rtp. I have a loader process which
then spawns all the other processes in the app. The first line in the
loader is:

// become session leader
if (setsid() == -1)
perror("setsid error: ");

Under qnx4 this works great, neutrino says “Operation not permitted”.

Any idea why? Thanks.

Your process is likely already a process group leader, and
this will cause the setsid to fail with this error. ksh under
QNX4 does not start a new process group when it starts an app,
but under Nto it will, so if you are starting the loader from
ksh that’s likely your problem.

-Peter

Bruce Davis <bruce.r.davis@boeing.com> wrote:
: I am trying to port my qnx4 app to rtp. I have a loader process which
: then spawns all the other processes in the app. The first line in the
: loader is:

: // become session leader
: if (setsid() == -1)
: perror("setsid error: ");

: Under qnx4 this works great, neutrino says “Operation not permitted”.

: Any idea why? Thanks.

Thanks for the response. I wrote a little program to load my loader by
spawing it, and that got rid of the setsid error, but I am not getting
the same behavior I got under qnx4. The reason I am making the loader a
session leader is so that all the children (i.e., all the processes that
make up my application) will be killed when I slay the loader. That
works great under qnx4 but it doesn’t happen under nto. Shouldn’t the
other processes terminate when their session leader terminates?

Peter Graves wrote:

Your process is likely already a process group leader, and
this will cause the setsid to fail with this error. ksh under
QNX4 does not start a new process group when it starts an app,
but under Nto it will, so if you are starting the loader from
ksh that’s likely your problem.

-Peter

Bruce Davis <> bruce.r.davis@boeing.com> > wrote:
: I am trying to port my qnx4 app to rtp. I have a loader process which
: then spawns all the other processes in the app. The first line in the
: loader is:

: // become session leader
: if (setsid() == -1)
: perror("setsid error: ");

: Under qnx4 this works great, neutrino says “Operation not permitted”.

: Any idea why? Thanks.

Are you setting a controlling terminal for your new sessions?
You need to have a controlling terminal for the SIGHUP (I am
guessing this is the signal you are expecting) to be delivered to
the child processes. This didn’t seem to be needed under QNX4, but
if I read correctly in the trusty POSIX book this morning it
should be necessary. So if you do something like:

setsid();
ioctl(0,TIOCSCTTY,NULL);

It should set the device stdin is connected to, to be the
controlling terminal for the session and when it is closed
by the session leader, all members of the forground process
group in that session should recieve a SIGHUP.

-Peter


Bruce Davis <bruce.r.davis@boeing.com> wrote:
: Thanks for the response. I wrote a little program to load my loader by
: spawing it, and that got rid of the setsid error, but I am not getting
: the same behavior I got under qnx4. The reason I am making the loader a
: session leader is so that all the children (i.e., all the processes that
: make up my application) will be killed when I slay the loader. That
: works great under qnx4 but it doesn’t happen under nto. Shouldn’t the
: other processes terminate when their session leader terminates?

: Peter Graves wrote:
:>
:> Your process is likely already a process group leader, and
:> this will cause the setsid to fail with this error. ksh under
:> QNX4 does not start a new process group when it starts an app,
:> but under Nto it will, so if you are starting the loader from
:> ksh that’s likely your problem.
:>
:> -Peter
:>
:> Bruce Davis <bruce.r.davis@boeing.com> wrote:
:> : I am trying to port my qnx4 app to rtp. I have a loader process which
:> : then spawns all the other processes in the app. The first line in the
:> : loader is:
:>
:> : // become session leader
:> : if (setsid() == -1)
:> : perror("setsid error: ");
:>
:> : Under qnx4 this works great, neutrino says “Operation not permitted”.
:>
:> : Any idea why? Thanks.

Looks like I may have lied a bit there, just got a email
to correct me… Went back and reread some and…

The basic problem is likely the lack of controlling terminal,
but you probably don’t want to just ioctl it to stdin, as this
may steal the controlling terminal from the parent process (A
terminal may be the controlling terminal for at most one session).
I just played around with this a bit more and it does look like
it will cause some problems with the shell if you do this (you
loose ^z ^c etc.) But if you open another terminal device(pty?)
you should be able to make that your controling terminal (this
may happen just by opening a terminal device that is not already
a controling terminal, I am not %100 sure).

Also, the closing of the controling terminal is not what will
trigger the SIGHUP, but the termination of the session
leader.

Note, I am by no means an expert on sessions and such, so if
someone sees any big holes in what I just said feel free to
pipe in. :slight_smile:

-Peter



Peter Graves <pgraves@qnx.com> wrote:
: Are you setting a controlling terminal for your new sessions?
: You need to have a controlling terminal for the SIGHUP (I am
: guessing this is the signal you are expecting) to be delivered to
: the child processes. This didn’t seem to be needed under QNX4, but
: if I read correctly in the trusty POSIX book this morning it
: should be necessary. So if you do something like:

: setsid();
: ioctl(0,TIOCSCTTY,NULL);

: It should set the device stdin is connected to, to be the
: controlling terminal for the session and when it is closed
: by the session leader, all members of the forground process
: group in that session should recieve a SIGHUP.

: -Peter


: Bruce Davis <bruce.r.davis@boeing.com> wrote:
: : Thanks for the response. I wrote a little program to load my loader by
: : spawing it, and that got rid of the setsid error, but I am not getting
: : the same behavior I got under qnx4. The reason I am making the loader a
: : session leader is so that all the children (i.e., all the processes that
: : make up my application) will be killed when I slay the loader. That
: : works great under qnx4 but it doesn’t happen under nto. Shouldn’t the
: : other processes terminate when their session leader terminates?

: : Peter Graves wrote:
: :>
: :> Your process is likely already a process group leader, and
: :> this will cause the setsid to fail with this error. ksh under
: :> QNX4 does not start a new process group when it starts an app,
: :> but under Nto it will, so if you are starting the loader from
: :> ksh that’s likely your problem.
: :>
: :> -Peter
: :>
: :> Bruce Davis <bruce.r.davis@boeing.com> wrote:
: :> : I am trying to port my qnx4 app to rtp. I have a loader process which
: :> : then spawns all the other processes in the app. The first line in the
: :> : loader is:
: :>
: :> : // become session leader
: :> : if (setsid() == -1)
: :> : perror("setsid error: ");
: :>
: :> : Under qnx4 this works great, neutrino says “Operation not permitted”.
: :>
: :> : Any idea why? Thanks.