starting a program on another node

We are trying to start a module on another node and are having some issues.
We are using qnx_spawn and are able to start the module and all is well
however, there are virtual circuits open with the module and Dev32.

Is there any way to start a module on another node without having any
attachments to the node that is initiating the module.

Thanks.

What you are seeing is most likely connections to stdin, stdout and stderr.
This allows the program to do terminal IO to/from the terminal that started
it (actually it’s parent). You can:

  1. spawn the new program with fds 0, 1 and 2 closed
  2. spawn the new program with fds 0, 1 and 2 open to some device on the node
    that you want to execute the new program
  3. if you are writing the program yourself, close fds 0, 1 and 2 after the
    program starts.

“Doug Rixmann” <rixmannd@rdsdata.com> wrote in message
news:a7t899$lhr$1@inn.qnx.com

We are trying to start a module on another node and are having some
issues.
We are using qnx_spawn and are able to start the module and all is well
however, there are virtual circuits open with the module and Dev32.

Is there any way to start a module on another node without having any
attachments to the node that is initiating the module.

Thanks.

Doug Rixmann <rixmannd@rdsdata.com> wrote:

We are trying to start a module on another node and are having some issues.
We are using qnx_spawn and are able to start the module and all is well
however, there are virtual circuits open with the module and Dev32.

Is there any way to start a module on another node without having any
attachments to the node that is initiating the module.

Have you been able to get the behaviour you want with the “on”
utility? It gives a bunch of command line options for starting
on another node, on another device etc.

Once you’ve got that worked out…here is the source to on, to duplicate
the behaviour you want in C source.

-David
QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.


#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <process.h>
#include <fcntl.h>
#include <ctype.h>

#include <sys/prfx.h>
#include <sys/qnx_glob.h>

/* define an abbreviation for the global spawn option to make the code
lines shorter and to save typing */
#define qso qnx_spawn_options

#include <sys/sched.h>
#include <sys/wait.h>
#include <sys/vc.h>

#ifdef __USAGE
%C - execute a command on another node or tty (QNX)

%C [-d] [-h] [-n node] [-r root] [-t tty] command
Options:
-d detach (nozombie)
-f nid spawn from remote node
-h spawn held
-n nid spawn on remote node
-p prio spawn with priority
-r root override default network root
-s spawn new process group
-t tty spawn new session on tty
#endif

static char *progname = “$Id: on.c,v 1.13 1993/11/17 15:17:56 brianc Exp $”;

void main(int argc, char **argv) {
int overlay = P_OVERLAY;
char buffer[8] = “//”;
int status;
int ch;

if (*(progname = basename(*argv)) == ‘-’) progname++;

while ((ch = getopt(argc, argv, “Ddf:hn:p:r:st:”)) != EOF) {
switch (ch) {
case ‘D’: /* debug /
qso.flags |= _SPAWN_DEBUG;
break;
case ‘d’: /
detach /
qso.flags |= _SPAWN_NOZOMBIE;
break;
case ‘h’: /
hold /
qso.flags |= _SPAWN_HOLD;
break;
case ‘f’: /
from /
qnx_prefix_setroot(strcat(buffer, optarg));
/
fallthru /
case ‘n’: /
remote /
qso.node = qnx_strtonid(optarg, 0);
if (qso.node == -1 || qso.node == 0) {
fprintf(stderr, “%s: %s (%s)\n”, progname, “invalid node”, optarg);
exit(EXIT_FAILURE);
} else if (qso.node != getnid())
overlay = P_NOWAIT;
break;
case ‘p’: /
priority */
qso.priority = strtol(optarg, &optarg, 0);
switch (optarg) {
case ‘f’: qso.sched_algo = SCHED_FIFO; break;
case ‘o’: qso.sched_algo = SCHED_OTHER; break;
case ‘r’: qso.sched_algo = SCHED_RR; break;
}
break;
case ‘r’: /
metaroot /
qnx_prefix_setroot(optarg);
break;
case ‘s’: /
session /
qso.flags |= _SPAWN_NEWPGRP;
break;
case ‘t’: /
tty */
close(0);
if (open(optarg, O_RDWR) < 0) {
fprintf(stderr, “%s: %s (%s)\n”, progname, strerror(errno), optarg);
exit(EXIT_FAILURE);
}
dup2(qso.ctfd = 0, 1), dup2(1, 2);
qso.flags |= _SPAWN_SETSID | _SPAWN_TCSETPGRP;
overlay = P_NOWAIT;
break;
}
}

if (optind == argc)
if (qso.priority == (char)-1 && qso.sched_algo == (char)-1)
print_usage(argv);
else
exit(qnx_scheduler(0, getppid(), qso.sched_algo, qso.priority, 0) == -1);

argv += optind;
if ((status = spawnvp(overlay, *argv, argv)) == -1)
fprintf(stderr, “%s: %s (%s)\n”, progname, strerror(status = errno), *argv);
else if ((qso.flags & _SPAWN_SETSID) == 0) {
signal(SIGINT, SIG_IGN), signal(SIGQUIT, SIG_IGN);
close(0), close(1), close(2), fcloseall();
if (waitpid(status, &status, 0) == -1)
fprintf(stderr, “%s: %s (%s)\n”, progname, strerror(status = errno), *argv);
else if (WIFSIGNALED(status)) {
status = WTERMSIG(status);
signal(status, SIG_DFL);
raise(status);
} else if (WIFEXITED(status))
status = WEXITSTATUS(status);
}
exit(status);
}