Re: concurrent calls to system(const char *)
- From: Tim Roberts <timr@xxxxxxxxx>
- Date: Sat, 12 Jan 2008 04:39:33 GMT
anthony.geay@xxxxxxxxx wrote:
I'm trying to launch concurrently in a same process in C++ code,
several independant shell scripts by calling
"int system(const char *)". Look at the bottom code.
When I launch the code, randomly it bugs with the following message
"/bin/sh: bad interpreter: file busy" (if it does not bug on your
computer you can increase
...
Should somebody have any idea of the reason it bugs randomly ?
...
void *f(void *st)
{
std::ostringstream st1;
st1 << "yacs" << *((int *) st);
mkdir(st1.str().c_str(), 00777);
...
int main()
{
pthread_t threadId[NB_OF_THREADS];
for(int i=0;i<NB_OF_THREADS;i++)
{
int *smth=new int(i);
pthread_create(threadId+i,0,f,smth);
}
This has a rather large memory leak, in that you never free all those
integers. Fortunately, you don't NEED to allocate new memory for these.
The context parameter is declared as a pointer, but that doesn't mean you
have to pass the address of something. You can just pass the thread number
directly:
void *f( void * st )
{
std::ostringstream st1;
st1 << "yacs" << (int)st;
mkdir(st1.str().c_str(), 0777);
...
for(int i=0; i < NB_OF_THREADS; i++ )
{
pthread_create(threadId+i, 0, (void*)i, smth );
...
Why do you do the open/close/open thing?
--
Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.
.
- Follow-Ups:
- Re: concurrent calls to system(const char *)
- From: Rainer Weikusat
- Re: concurrent calls to system(const char *)
- References:
- concurrent calls to system(const char *)
- From: anthony . geay
- concurrent calls to system(const char *)
- Prev by Date: Re: Question on interrupt stats and probe
- Next by Date: Re: serial port does not work on PC104
- Previous by thread: Re: concurrent calls to system(const char *)
- Next by thread: Re: concurrent calls to system(const char *)
- Index(es):
Relevant Pages
|