process creation using spawn

I am new to QNX programming.I was trying to create processes using the spawn function using the below code,
/*
*

  • This is an example of a parent process that creates some child
  • processes */

#include <spawn.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <errno.h>
#include <sys/mount.h>

int main(int argc, char **argv)
{
char *args[] ={ “001”, NULL };
int i, status;
pid_t pid;
struct inheritance inherit;
int errvalue;
errno = EOK;
inherit.flags = 0;
pid = spawn(“001”, 0, NULL, &inherit, args, environ);
printf(“spawned child1, pid = %d\n”, pid);
errvalue = errno;
printf( “The error generated was %d\n”, errvalue );
printf( “That means: %s\n”, strerror( errvalue ) );
}

output of abhove program is:
spawned child1, pid = -1
The error generated was 2
That means: No such file or directory

In above program i am not able to create processes using spawn
can anyone help me,where i am getting wrong.
I am new to QNX programming anyhelp would be of great help

You don’t initialize the content of the structure inherit aside one variable. The other fields contain garbage.

I assume 001 is a program? The first field should be the FULL path, assuming the 001 program is not in a directory pointed by the environment variable PATH.

First of all Thanks for the reply,i am not able to provide the correct path.the FULL path would be the exe name or the path of exe. or something else.Whichever way i do same error occurs.

in the path i have given “/tmp” as parameter in spawn

error:spawn() failed: Permission denied
spawn child,pid=-1
plz reply

This works to launch “pidin”, but unless you have special requirements, it is MUCH easier to call system( “/bin/pidin” ). …also consider the simpler spawnle().

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <spawn.h>
#include <errno.h>

int main( int argc, char **argv )
{
char *args[] ={ “/bin/pidin”, NULL };
struct inheritance inherit;
pid_t pid;

  memset( &inherit, 0, sizeof(inherit) );
  pid = spawn( "/bin/pidin", 0, NULL, &inherit, args, environ );
  if ( pid == -1 )
  {
        printf( "The error generated was %d\n", errno );
        printf( "That means: %s\n", strerror( errno ) );
  }
  else
        printf("spawned child1, pid = %d\n", pid);

}

Thanks for the reply,now spawn is working,would run spawnle() too…presently trying to work with resouce manager to drive a serial port…