View topic - spawnv failure
spawnv failure
14 posts
• Page 1 of 1
spawnv failure
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.
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
EBADF
An error occurred duplicating open file descriptors to the new process.
Does that suggest anything?
An error occurred duplicating open file descriptors to the new process.
Does that suggest anything?
- maschoen
- QNX Master
- Posts: 2657
- Joined: Wed Jun 25, 2003 5:18 pm
Re: spawnv failure
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
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: 2657
- Joined: Wed Jun 25, 2003 5:18 pm
Re: spawnv failure
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
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.
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
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: 2657
- Joined: Wed Jun 25, 2003 5:18 pm
Re: spawnv failure
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
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

- wednesday
- Active Member
- Posts: 48
- Joined: Tue Apr 28, 2009 7:10 am
Re: spawnv failure
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
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: 2657
- Joined: Wed Jun 25, 2003 5:18 pm
Re: spawnv failure
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
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: 2657
- Joined: Wed Jun 25, 2003 5:18 pm
Re: spawnv failure
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
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: 2657
- Joined: Wed Jun 25, 2003 5:18 pm
Re: spawnv failure
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?
Could that cause any issue?
- wednesday
- Active Member
- Posts: 48
- Joined: Tue Apr 28, 2009 7:10 am
14 posts
• Page 1 of 1
Return to Realtime and Embedded
Who is online
Users browsing this forum: nico04 and 4 guests