Hi. I’m porting a QNX 4 app to Neutrino. I have a program that does
approximately the following:
int main()
{
// parse command line
// put ourselves in background. Under QNX 4, this was a call to
// fork() followed by a call to setsid(). I can no longer do the
// fork() because this process is multithreaded.
//fork();
setsid();
// attach name
name_attach(NULL, “faac/program”, 0);
// create a thread
pthread_create(…network_listener…);
// tons of other stuff
}
void *network_listener(void *)
{
// this hangs if I have setsid() enabled; works fine if setsid()
// is commented out. I need the coid in order to send pulses.
coid = name_open(“faac/program”);
}
If I leave the setsid call in, the name_open hangs. If I comment out
the setsid, things function more or less as I expect. Why?
Attached is the source to a short program that duplicates the problem,
as well as a shell script to start it (if the program is started
directly from shell, setsid fails because the process is already a leader).
I’m sure there are other cleaner, more Neutrino-ish ways of doing this;
what I have so far is more-or-less a direct translation of the QNX 4 code.
In a somewhat related problem in a different process, spawn() seems to
fail if I add the SPAWN_SETGROUP flag. Has anyone else gotten this to work?
In a more general sense, how exactly are sessions and process groups
handled in a multithreaded environment? If a signal is laid on a
session leader, do all threads within all processes in that session also
get the signal?
Josh Hamacher
FAAC Incorporated