Starting an app that doesn't need the shell

Hi,
I’m having a problem that I’m sure is easy, I just can’t figure out how
to find the answer in the help.
I have a program that needs to run in the background, and I need to be
able to run it from a shell then close the shell without the program
dying. I know this is possible because I’ve seen it before, I’m just not
sure how to make it happen, can anyone point me in the right direction?
Thanks in advance,


Chris Nasr
cnasr[at]mechtronix[dot]ca
Mechtronix Systems Inc.

Previously, Chris Nasr wrote in qdn.public.qnx4:

Hi,
I’m having a problem that I’m sure is easy, I just can’t figure out how
to find the answer in the help.
I have a program that needs to run in the background, and I need to be
able to run it from a shell then close the shell without the program
dying. I know this is possible because I’ve seen it before, I’m just not
sure how to make it happen, can anyone point me in the right direction?
Thanks in advance,

Look at the nohup command.

Additionally you can:

  1. become a daemon process by:
  • fork(), terminate parent, child continues
  • setsid() in the child
  • ignore SIGHUP
  • fork(), terminate parent, child continues
  • close all open descriptors
  • log errors to your own log file or use syslogd
  1. ignore SIGHUP signals and start it in the background using &

“Ken Schumm” <kwschumm@IH8SPAMqsolv.com> wrote in message
news:Voyager.020204152200.15126A@dilbert…

Previously, Chris Nasr wrote in qdn.public.qnx4:
Hi,
I’m having a problem that I’m sure is easy, I just can’t figure out how
to find the answer in the help.
I have a program that needs to run in the background, and I need to be
able to run it from a shell then close the shell without the program
dying. I know this is possible because I’ve seen it before, I’m just not
sure how to make it happen, can anyone point me in the right direction?
Thanks in advance,


Look at the nohup command.

What is accomplished by the second fork() ?


Bill Caroselli – 1(626) 824-7983
Q-TPS Consulting
QTPS@EarthLink.net


“Brown, Richard” <brownr@aecl.ca> wrote in message
news:a3oh0i$g9s$1@inn.qnx.com

Additionally you can:

  1. become a daemon process by:
  • fork(), terminate parent, child continues
  • setsid() in the child
  • ignore SIGHUP
  • fork(), terminate parent, child continues
  • close all open descriptors
  • log errors to your own log file or use syslogd
  1. ignore SIGHUP signals and start it in the background using &

“Ken Schumm” <> kwschumm@IH8SPAMqsolv.com> > wrote in message
news:Voyager.020204152200.15126A@dilbert…
Previously, Chris Nasr wrote in qdn.public.qnx4:
Hi,
I’m having a problem that I’m sure is easy, I just can’t figure out
how
to find the answer in the help.
I have a program that needs to run in the background, and I need to be
able to run it from a shell then close the shell without the program
dying. I know this is possible because I’ve seen it before, I’m just
not
sure how to make it happen, can anyone point me in the right
direction?
Thanks in advance,


Look at the nohup command.

I had to go back to the UNIX Network Programming book for this :

In some UNIXs if a session leader without a controlling terminal opens a
terminal device then that terminal device becomes the controlling terminal.

The second fork makes the child a non-session leader and thus ensures that
it will never have a controlling terminal.

“Bill Caroselli” <qtps@earthlink.net> wrote in message
news:a3oqhf$n3c$1@inn.qnx.com

What is accomplished by the second fork() ?


Bill Caroselli – 1(626) 824-7983
Q-TPS Consulting
QTPS@EarthLink.net


“Brown, Richard” <> brownr@aecl.ca> > wrote in message
news:a3oh0i$g9s$> 1@inn.qnx.com> …
Additionally you can:

  1. become a daemon process by:
  • fork(), terminate parent, child continues
  • setsid() in the child
  • ignore SIGHUP
  • fork(), terminate parent, child continues
  • close all open descriptors
  • log errors to your own log file or use syslogd
  1. ignore SIGHUP signals and start it in the background using &

“Ken Schumm” <> kwschumm@IH8SPAMqsolv.com> > wrote in message
news:Voyager.020204152200.15126A@dilbert…
Previously, Chris Nasr wrote in qdn.public.qnx4:
Hi,
I’m having a problem that I’m sure is easy, I just can’t figure out
how
to find the answer in the help.
I have a program that needs to run in the background, and I need to
be
able to run it from a shell then close the shell without the program
dying. I know this is possible because I’ve seen it before, I’m just
not
sure how to make it happen, can anyone point me in the right
direction?
Thanks in advance,


Look at the nohup command.

\

Richard,
thanks, I trapped SIGHUP and that fixed my problem. Much appreciated.

Chris

“Brown, Richard” wrote:

Additionally you can:

  1. become a daemon process by:
  • fork(), terminate parent, child continues
  • setsid() in the child
  • ignore SIGHUP
  • fork(), terminate parent, child continues
  • close all open descriptors
  • log errors to your own log file or use syslogd
  1. ignore SIGHUP signals and start it in the background using &

“Ken Schumm” <> kwschumm@IH8SPAMqsolv.com> > wrote in message
news:Voyager.020204152200.15126A@dilbert…
Previously, Chris Nasr wrote in qdn.public.qnx4:
Hi,
I’m having a problem that I’m sure is easy, I just can’t figure out how
to find the answer in the help.
I have a program that needs to run in the background, and I need to be
able to run it from a shell then close the shell without the program
dying. I know this is possible because I’ve seen it before, I’m just not
sure how to make it happen, can anyone point me in the right direction?
Thanks in advance,


Look at the nohup command.


Chris Nasr
cnasr[at]mechtronix[dot]ca
Mechtronix Systems Inc.

Newbie here…
I am trying to accomplish the same thing, how do I ignore this SIGHUP signal?
The only way I see is by starting the process with qnx_Spawn()?

Keith

Chris Nasr wrote:

Richard,
thanks, I trapped SIGHUP and that fixed my problem. Much appreciated.

Chris

“Brown, Richard” wrote:

Additionally you can:

  1. become a daemon process by:
  • fork(), terminate parent, child continues
  • setsid() in the child
  • ignore SIGHUP
  • fork(), terminate parent, child continues
  • close all open descriptors
  • log errors to your own log file or use syslogd
  1. ignore SIGHUP signals and start it in the background using &

“Ken Schumm” <> kwschumm@IH8SPAMqsolv.com> > wrote in message
news:Voyager.020204152200.15126A@dilbert…
Previously, Chris Nasr wrote in qdn.public.qnx4:
Hi,
I’m having a problem that I’m sure is easy, I just can’t figure out how
to find the answer in the help.
I have a program that needs to run in the background, and I need to be
able to run it from a shell then close the shell without the program
dying. I know this is possible because I’ve seen it before, I’m just not
sure how to make it happen, can anyone point me in the right direction?
Thanks in advance,


Look at the nohup command.

\

Chris Nasr
cnasr[at]mechtronix[dot]ca
Mechtronix Systems Inc.

“Keith Vasilakes” <kvasilak@cyberoptics.com> wrote in message
news:3C98A0F2.4984B639@cyberoptics.com

Newbie here…
I am trying to accomplish the same thing, how do I ignore this SIGHUP
signal?
The only way I see is by starting the process with qnx_Spawn()?

Keith

Chris Nasr wrote:

Richard,
thanks, I trapped SIGHUP and that fixed my problem. Much appreciated.

Chris

“Brown, Richard” wrote:

Additionally you can:

  1. become a daemon process by:
  • fork(), terminate parent, child continues
  • setsid() in the child
  • ignore SIGHUP
  • fork(), terminate parent, child continues
  • close all open descriptors
  • log errors to your own log file or use syslogd
  1. ignore SIGHUP signals and start it in the background using &

“Ken Schumm” <> kwschumm@IH8SPAMqsolv.com> > wrote in message
news:Voyager.020204152200.15126A@dilbert…
Previously, Chris Nasr wrote in qdn.public.qnx4:
Hi,
I’m having a problem that I’m sure is easy, I just can’t figure
out how
to find the answer in the help.
I have a program that needs to run in the background, and I need
to be
able to run it from a shell then close the shell without the
program
dying. I know this is possible because I’ve seen it before, I’m
just not
sure how to make it happen, can anyone point me in the right
direction?
Thanks in advance,


Look at the nohup command.

\

Chris Nasr
cnasr[at]mechtronix[dot]ca
Mechtronix Systems Inc.

#include <sys/types.h

#include <sys/stat.h>
#include <fcntl.h>
#include <stddef.h>
#include <process.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

void main
(
int argc,
char *argv[]
)
{
char fname[32]; // gets filename from argv 0

if (argc != 2)
{
printf(“detach progpath\n”);
exit(1);
}

if (fork())
exit(0);

close(0);
close(1);
close(2);

open("/dev/con1", O_RDONLY);
open("/home/manila/detach.log", O_WRONLY | O_CREAT | O_APPEND);
open("/home/manila/detach.log", O_WRONLY | O_CREAT | O_APPEND);

if (-1 == setsid())
{
perror(“Couldn’t setsid”);
exit(1);
}

_splitpath(argv[1],
0, // node
0, // dir
fname, // filename
0); // extension

execl(argv[1], fname, 0);

perror(“Couldn’t exec”);
exit(1);
}

signal( SIGHUP, SIG_IGN );

“Keith Vasilakes” <kvasilak@cyberoptics.com> wrote in message
news:3C98A0F2.4984B639@cyberoptics.com

Newbie here…
I am trying to accomplish the same thing, how do I ignore this SIGHUP
signal?
The only way I see is by starting the process with qnx_Spawn()?

Keith

Chris Nasr wrote:

Richard,
thanks, I trapped SIGHUP and that fixed my problem. Much appreciated.

Chris

“Brown, Richard” wrote:

Additionally you can:

  1. become a daemon process by:
  • fork(), terminate parent, child continues
  • setsid() in the child
  • ignore SIGHUP
  • fork(), terminate parent, child continues
  • close all open descriptors
  • log errors to your own log file or use syslogd
  1. ignore SIGHUP signals and start it in the background using &

“Ken Schumm” <> kwschumm@IH8SPAMqsolv.com> > wrote in message
news:Voyager.020204152200.15126A@dilbert…
Previously, Chris Nasr wrote in qdn.public.qnx4:
Hi,
I’m having a problem that I’m sure is easy, I just can’t figure
out how
to find the answer in the help.
I have a program that needs to run in the background, and I need
to be
able to run it from a shell then close the shell without the
program
dying. I know this is possible because I’ve seen it before, I’m
just not
sure how to make it happen, can anyone point me in the right
direction?
Thanks in advance,


Look at the nohup command.

\

Chris Nasr
cnasr[at]mechtronix[dot]ca
Mechtronix Systems Inc.