Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

Call to system() makes the application stuck

 
Highlighted
Yulia Vilensky
Occasional Advisor

Call to system() makes the application stuck

Hi,
The OS is HP-UX 11i.
We have a multithreaded application that should call for some bush shell script.

The call to system() makes the application stuck and just reboot helps.
Do you have any idea what makes it stuck?
6 REPLIES 6
Highlighted
Peter Godron
Honored Contributor

Re: Call to system() makes the application stuck

Hi,
and welcome to the forums !

Is the system call successful. Have you put a debug statment at the top of your external shell script ? Are you using exit to terminate the shell ?
What is the return status of your system() call ?

Please read:
http://66.34.90.71/ITRCForumsEtiquette/after.html

Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33
on how to reward any useful answers given to your questions.

Highlighted
Yulia Vilensky
Occasional Advisor

Re: Call to system() makes the application stuck

The system call never returns.
The debug statement at the top of the shell script is never printed. We use exit to terminate the shell.
We have alredy an idea regarding the problem: the father thread of the thread that calls to system() blocks SIGCHLD.
We are working on checking if it's the real problem.
Thanks, Yulia
Highlighted
Yulia Vilensky
Occasional Advisor

Re: Call to system() makes the application stuck

It seems that the problem isn't in blocking any signals.
We created a sample executable, that creates a thread (see the code below).
The threadEntryFunc just calls to system() to perform an echo command (even not the script mentioned above).
When the executable runs for the first time, we can see prints from threadEntryFunc , but the system call seems not to be performed. For the second time we don't see even the prints from threadEntryFunc .

int main()
{
pthread_attr_t attr;
pthread_t threadId = 0;
int rc;

pid_t pid = getpid();
printf("the pid of the father process is %d\n", pid);


/* create thread */
rc = pthread_attr_init(&attr);
if (rc) {
return rc;
}

rc = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (rc) {
pthread_attr_destroy(&attr);
return rc;
}

rc = pthread_create(&threadId,
&attr,
threadEntryFunc,
(void*)NULL);

if (rc) {
printf("failed to crate thread\n");
pthread_attr_destroy(&attr);
}

printf("after thread function the thread id that was created is %d \n ",
threadId );

return 0;
}
Highlighted
Peter Godron
Honored Contributor

Re: Call to system() makes the application stuck

Hi,
you may want to read the following thread on output redirect:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1134584

When you debug the code where does the focus go to ? Does the system attempt to execute the system call but never returns, as it still waiting as to what to do with the output ?
Highlighted
Yulia Vilensky
Occasional Advisor

Re: Call to system() makes the application stuck

Hi,
It seems that the call never returns.

How do you suggest to use popen() instead of system()?
If yes, it seems it doesn't help.

What do you think the problem is?

I want to admit that there wasn't any problem in calling to system() if no new thread is created, i.e. the application is single-threaded
Highlighted
Dennis Handly
Acclaimed Contributor

Re: Call to system() makes the application stuck

>The call to system() makes the application stuck and just reboot helps.

No need to reboot your system. A kill or kill -9 should clean it up.

>We created a sample executable, that creates a thread (see the code below). The threadEntryFunc just calls to system() to perform an echo command

I have no problems with your sample script, provided I wait until all of the threads are done. I use sleep(10).

>How do you suggest to use popen() instead of system()? If yes, it seems it doesn't help.

This is likely to hang in the exact same way.

>What do you think the problem is?

You need to run tusc to see what exactly is happening.

How many of your threads is trying to execute system(3)? You should really only have one thread calling system(3).