Title |
Remotely spawning QNX apps and Photon applications |
Ref. No. |
QNX.000000980 |
Category(ies) |
Development |
Issue |
Is there a way to spawn QNX and Photon applicationss remotely from one machine to another? Then, turn off the local machine, and have the application still run on the other machine?
|
Solution |
The following is an example for remote spawning of a QNX application:
#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> #include <sys/wait.h> #include <sys/vc.h> #include <dirent.h> #define qso qnx_spawn_options void main(int argc, char **argv) { int overlay = P_OVERLAY; char buffer[8] = "//"; int status; int ch, i; char dir[80]; char *ph_argv[4]; char phapp[80]; char suffix[20]; DIR *dirp; struct dirent *direntp; pid_t pid;
if (argc != 3) { fprintf(stderr,"Use:onq node QnxApp"); exit (1); } qso.flags |= _SPAWN_NOZOMBIE; /* remote */ qso.node = qnx_strtonid(argv[1], 0); if (qso.node == -1 || qso.node == 0) { fprintf(stderr, "invalid node"); exit(3); } else if (qso.node != getnid()) overlay = P_NOWAIT; strcat(buffer, argv[1]); strcat(buffer, "/"); qnx_prefix_setroot(buffer); if(!(strcmp(argv[0], "onq") ) ) { // QNX terminal mode - use /node/dev/con // this will use first free console strcat(buffer, "dev/con"); close(0); if (open(buffer, O_RDWR) <0) { fprintf(stderr, "error opening /dev/con - probably no free consoles "); exit(4); } dup2(qso.ctfd = 0, 1), dup2(1, 2); qso.flags |= _SPAWN_SETSID | _SPAWN_TCSETPGRP; overlay = P_NOWAIT; argv += 2; if ((status = spawnvp (overlay, *argv, argv)) == -1) fprintf(stderr,"Spawn fail:%s",errno); else if ((qso.flags&_SPAWN_SETSID)==0) { signal(SIGINT, SIG_IGN), signal(SIGQUIT, SIG_IGN); close(0), close(1), close(2), fcloseall(); } exit(0); } }
And here is the code to do the same thing for a Photon application:
/* Standard headers */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/vc.h> #include <sys/name.h> #include <sys/kernel.h>
/* Extra headers */ #include <fcntl.h> #include <process.h> #include <sys/qnx_glob.h>
void main(int argc, char **argv) { char dir[80]; char *myargv[4]; char suffix[20]; pid_t pid; nid_t rnid; int fd;
/* Get the entered Node Number */ rnid = qnx_strtonid(argv[1], 0); /* Look for Photon */ strcpy(dir, "//"); strcat(dir, argv[1]); strcat(dir, "/dev/photon"); fd = open(dir, O_RDONLY); if(fd != -1) { myargv[0] = "/usr/photon/bin/pterm"; strcpy(suffix, "-s//"); strcat(suffix, argv[1]); strcat(suffix, "/dev/photon"); myargv[1] = suffix; // Photon server myargv[2] = NULL; // "-s" works for all PhAB apps - attach to //specified Photon server */ strcpy(dir, "//"); strcat(dir, argv[1]); strcat(dir, "/"); qnx_prefix_setroot(dir); pid = qnx_spawn( 0, 0, rnid, -1, -1, 0, myargv[0], myargv, environ, NULL, -1); if ( pid <0 ) perror("spawn"); } close(fd); return; } |
|