problem with spawnl

i am unable to spawnl after receiving a pluse from the timer…

not understanding wether it is problem with channel connect in timer or with spawnl function.

I think we’d need more info. Does spawnl() return an error code?

No spawnl() doesnot return any error. following is the code, for your refernce:

#include <stdio.h>
#include <process.h>

void setupPulseAndTimer (void)
{
timer_t timerid1; // timer ID for timer
struct sigevent event1; // event to deliver
struct itimerspec timer1; // the timer data struct
int coid; // connection back to us

coid = ConnectAttach (0, 0, chid, 0, 0); 								    // create a connection back to ourselves

if (coid == -1) 
{
    printf("Cannot Attach\n");
    perror (NULL);
    exit (EXIT_FAILURE);
}

 SIGEV_PULSE_INIT (&event1, coid, SIGEV_PULSE_PRIO_INHERIT, CODE_TIMER, 0); 	// Setting the event as Pulse

if (timer_create (CLOCK_REALTIME, &event1, &timerid1) == -1) 							// create the timer, binding it to the event
{	
	printf("Cannot Create Timer\n");;
    perror (NULL);
    exit (EXIT_FAILURE);
}

// setup the timer (10ms delay, 1ms reload)
timer1.it_value.tv_sec = 1;
timer1.it_value.tv_nsec = 0;
timer1.it_interval.tv_sec = 1;
timer1.it_interval.tv_nsec = 0;

// and start it!
timer_settime (timerid1, 0, &timer1, NULL);

}

void process_routine(void)
{
spawnl(P_NOWAIT,"/root/process2","/root/process2",NULL);
}

int main (void) // ignore command-line arguments
{
int rcvid,x=0; // process ID of the sender
MessageT msg; // the message itself

if ((chid = ChannelCreate (0)) == -1) 										// Create Channel for communication for timer signals
{
    printf("Couldn't create channel!\n");
    exit (EXIT_FAILURE);
}

																			// Configure the Analog Input Card.	

setupPulseAndTimer ();																	// set up the pulse and timer

for(;;)
{
   rcvid = MsgReceive (chid, &msg, sizeof (msg), NULL); 			// receiving messages
   if (rcvid == 0)  																		// determine who the message came from
   {
	printf("\n");
		process_routine();
	   } 
   else 
   {
	  	printf("Error in receiving Pulse from timer \n");
   }
 }
return (EXIT_SUCCESS);

}

In the above program, a timer is created to generate a pulse for every 1 second. after receving the pulse, a process has to be invoked using spawnl() function. but by executing the program in GDB mode, we found that child process is created but acknowldgement MSG is not recevied by the parent process and hence the control gets stuck.
Kindly help us.

Csepl,

How is the spawned process supposed to send a message back to the parent.

In other words, what does the spawned process code look like and how will that process find the channel of the parent?

From the code it looks like the child is spawned since you don’t get an error code (I assume you get a valid pid). But I suspect the problem is the child process isn’t able to connect back to the parent to deliver the message. Thus that’s the code we need to see.

Tim

You must setup a signal handler to handle SIGCHLD and call wait()/waitpid() when the child dies.

@Tim

I am new to QNX…Kindly help me…
Child Process just have a printf statement…To be more specific my problem is after creating a timert and receiving a pluse i want to spawn a child process…which is not happening from the above code…

Thanks in advance.

Csepl,

Can I ask why you are doing this spawnl from a design point. Is this an acedemic exercise or do you really want to use this in a design?

In other words, what’s wrong with just starting a thread instead of a whole other process.

If you truly need te spawnl you are going to need the signal handler and wait/waitpid calls Mario mentions.

Tim

First csepl, when you post code make sure it compiles and also make sure you enable warning when compiling.

That being said you’re problem is not an easy one for a newbie. I assume this is for some sort of school assignment so I won’t make it easy on you :wink: In the documentation loop up _NTO_COF_CLOEXEC. Also, not relevant to your problem but worth checking out _NTO_SIDE_CHANNEL.