Skip navigation.
Home
The QNX Community Portal

View topic - spawnv failure

spawnv failure

For discussion of realtime and/or embedded programming.

spawnv failure

Postby wednesday » Thu Jan 31, 2013 10:34 am

Hi.
I have an application which spawns several other processes.
I have used spawnv call for each process as below for this purpose:
char** const ExecutablePath = argv ;
pid_t childProcessID = spawnv(P_NOWAITO,ExecutablePath[0],ExecutablePath);
if(-1 == childProcessID)
{
//Log failure with errno
cout<<"spwanv failed"<<errno<<endl;
}
where argv is {"full path to execultable",CommandLineParameters,NULL};

On some occasion i have observed spawnv is failing returning -1 and errno 9(EBADF)
What could be possible reason for this? Also it happens very rarely and is not reproducible.
wednesday
Active Member
 
Posts: 48
Joined: Tue Apr 28, 2009 7:10 am

Re: spawnv failure

Postby maschoen » Thu Jan 31, 2013 1:17 pm

EBADF
An error occurred duplicating open file descriptors to the new process.

Does that suggest anything?
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Re: spawnv failure

Postby wednesday » Fri Feb 01, 2013 4:11 am

I didnt exactly get what it would mean? Any ideas ????
wednesday
Active Member
 
Posts: 48
Joined: Tue Apr 28, 2009 7:10 am

Re: spawnv failure

Postby maschoen » Fri Feb 01, 2013 8:21 am

wednesday wrote:I didnt exactly get what it would mean? Any ideas ????


A process has file descriptors. They start at 0 and go up. Usually the first three are:

0 - stdin
1 - stdout
2 - stderr

which are opened by the shell when the process is created.

In QNX these are "attached" to a specific resource manager, not always the same one.
When you run spawn, the open fd's are duplicated. There is a system call dup() that does this.
The result is that the spawned program inherits these fd's.

The error is saying that the dup() is failing for some fd. There are many reasons that this could occur.
While unlikely, there are system and resource manager limits to the number of open fd's.
It's also possible that a poorly written resource manager might cause dup() to fail for some reason.
What you might want to look into is what resources are open when this occurs.
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Re: spawnv failure

Postby wednesday » Mon Feb 04, 2013 10:46 am

Am quite sure that when am spawing these new processes the number of open fds is well below the upper limit defined.
wednesday
Active Member
 
Posts: 48
Joined: Tue Apr 28, 2009 7:10 am

Re: spawnv failure

Postby wednesday » Mon Feb 04, 2013 12:20 pm

A few more queries:
You mentioned about resource manager.As per my understanding its provided by QNX .So i dont have any control of how it works..so how can i control issues in that area .
Also in documentation its mentioned spawn will inherit all fds if fd_count =0 .In my case,since am using spawnv ,all desc will by default be inherited.Is it necessary to do so? Can i not skip this so that duplication of fds doesnt happen.
wednesday
Active Member
 
Posts: 48
Joined: Tue Apr 28, 2009 7:10 am

Re: spawnv failure

Postby maschoen » Mon Feb 04, 2013 6:18 pm

wednesday wrote:A few more queries:
You mentioned about resource manager.As per my understanding its provided by QNX .

Well most likely that is true. With QNX you can use provided resource managers, but you can provide your own. I don't know what you are doing, so I don't know if that is the case or not.
If the "failure" is in a QNX provided resource manager, it might help to know which one.


Also in documentation its mentioned spawn will inherit all fds if fd_count =0 .In my case,since am using spawnv ,all desc will by default be inherited.Is it necessary to do so? Can i not skip this so that duplication of fds doesnt happen.


Yes, you can skip this.
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Re: spawnv failure

Postby wednesday » Tue Feb 05, 2013 11:08 am

How can i skip inheriting parent's fds?Is it by using directly spawn instead of spawnv which my code currently uses?If so,what will be the values provided to fd_count and fd_array as setting fd_count =0 would inherit all desc by default.
However, I would like to know the real reason for spawnv failure.What wrong i could be doing possibly in my code ? I even tried to do a retry which is also failing with same errnum :x
wednesday
Active Member
 
Posts: 48
Joined: Tue Apr 28, 2009 7:10 am

Re: spawnv failure

Postby maschoen » Tue Feb 05, 2013 6:35 pm

wednesday wrote:How can i skip inheriting parent's fds?


One way would be to close all your fds before calling spawn.

Is it by using directly spawn instead of spawnv which my code currently uses?


Why not read the documentation and see.

However, I would like to know the real reason for spawnv failure.What wrong i could be doing possibly in my code ? I even tried to do a retry which is also failing with same errnum :x


I don't think we have enough information about your system to help you figure this out.
You could be doing something wrong, or you could be running up against a resource limitation, or you might be uncovering a QNX system bug.

Since retrying gets you the same error, it suggests that the problem is not intermittent.

Here's something you might try. When the error happens, call printf and write a really obvious message to yourself, and then call sleep(10000). Then manually in another shell run "pidin fds".
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Re: spawnv failure

Postby wednesday » Wed Feb 06, 2013 6:48 am

Thanks .I wil try and check for fds when i run in this scenario .But the issue i mentioned is v intermittent and not always reproducbile.
wednesday
Active Member
 
Posts: 48
Joined: Tue Apr 28, 2009 7:10 am

Re: spawnv failure

Postby maschoen » Wed Feb 06, 2013 7:21 am

wednesday wrote:Thanks .I wil try and check for fds when i run in this scenario .But the issue i mentioned is v intermittent and not always reproducbile.


You could try system("pidin fds >/tmp/log"); when it happens in your code, however I have a suspicion it too might fail since a spawn of /bin/sh is involved. In fact what suggested, running pidin in a shell might fail too, but that would suggest something about the problem, namely you are running out of some system resource.
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Re: spawnv failure

Postby wednesday » Wed Feb 06, 2013 10:02 am

I have changed code to log pidin through system() in a file .IF you suspect system might itself fail,i think i should even log failure of system . This will probably confirm if am running up against some resource limitation.
wednesday
Active Member
 
Posts: 48
Joined: Tue Apr 28, 2009 7:10 am

Re: spawnv failure

Postby maschoen » Wed Feb 06, 2013 6:40 pm

I'm not saying a system failure. I'm saying that you might be out of a resource at that time causing either system() or /bin/sh or pidgin to fail. In other words, nothing might happen.
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Re: spawnv failure

Postby wednesday » Thu Feb 07, 2013 6:29 am

One thing i forgot to mention is that my application which spawns other processes is a daemon(by using procmgr_daemon).
Could that cause any issue?
wednesday
Active Member
 
Posts: 48
Joined: Tue Apr 28, 2009 7:10 am


Return to Realtime and Embedded

Who is online

Users browsing this forum: No registered users and 2 guests