Hi,
I am facing a problem, while invoking a unix shell script through C++
code. I am using Pthreads to invoke shell scripts. Problem is that the
thread sometime invokes the scripts and sometime doesn't. Around 40%
of the time it fails to invoke the script.
Let me know your thoughts on this.
Thanks
Vinay
|
|
0
|
|
|
|
Reply
|
mugurvinay
|
2/22/2008 12:58:20 PM |
|
mugurvinay@gmail.com writes:
> I am facing a problem, while invoking a unix shell script through C++
> code. I am using Pthreads to invoke shell scripts. Problem is that the
> thread sometime invokes the scripts and sometime doesn't. Around 40%
> of the time it fails to invoke the script.
You have supplied no useful info whatsoever.
> Let me know your thoughts on this.
Please read this:
http://catb.org/esr/faqs/smart-questions.html
and try asking your question again, only smarter.
In particular:
- Exactly how do you "invoke shell scripts" (system? popen? fork/exec? something else?)
- How do you know that the script didn't get invoked?
- Did the thread that was supposed to invoke the script terminate?
If not, is it stuck somewhere? Where?
- Are you using pthread_atfork() handler(s)? If not, should you be?
.... etc... etc...
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
|
|
0
|
|
|
|
Reply
|
Paul
|
2/23/2008 3:21:16 AM
|
|
On Feb 23, 8:21=A0am, Paul Pluzhnikov <ppluzhnikov-...@gmail.com> wrote:
> mugurvi...@gmail.com writes:
> > I am facing a problem, while invoking a unix shell script through C++
> > code. I am using Pthreads to invoke shell scripts. Problem is that the
> >threadsometime invokes the scripts and sometime doesn't. Around 40%
> > of the time it fails to invoke the script.
>
> You have supplied no useful info whatsoever.
>
> > Let me know your thoughts on this.
>
> Please read this:
> =A0http://catb.org/esr/faqs/smart-questions.html
> and try asking your question again, only smarter.
>
> In particular:
> - Exactly how do you "invoke shell scripts" (system? popen? fork/exec? som=
ething else?)
> - How do you know that the script didn't get invoked?
> - Did thethreadthat was supposed to invoke the script terminate?
> =A0 If not, is it stuck somewhere? Where?
> - Are you using pthread_atfork() handler(s)? If not, should you be?
> ... etc... etc...
>
> Cheers,
> --
> In order to understand recursion you must first understand recursion.
> Remove /-nsp/ for email.
Hi,
Thanks for looking at my query.
1. I have attached the functions, which I have used to invoke thread,
and in turn to invoke the scripts
2. We have writing log from C++ code as well as from the script which
is being invoked. So, If i look at the C++ trace, I could see a entry
for an object Id (whic is unique) and the corresponding entry is not
present at the script trace file.
3. Since I am using, synchronous mode of ExpSpawnApplication, the
thread will be in block call status, until the script finishes its
work
CODE
bool TeMIPAlarmObjectUser::LaunchThread(Argument* pArgumentObj, const
RWCString& strInfo)
{
TraceMessage << "--> LaunchThread() Alarm ID =3D " <<
getId().getString() << endl;
bool bErrorOccured=3D false;
pthread_t threadId;
pthread_attr_t tattr;
int nReturnCode =3D pthread_attr_init(&tattr);
if (0 =3D=3D nReturnCode )
{
TraceMessage << "--- LaunchThread() pthread_attr_init success.
Size=3D" << sizeof(tattr) << endl;
nReturnCode =3D
pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_DETACHED);
if (0 =3D=3D nReturnCode)
{
nReturnCode =3D pthread_create(&threadId,&tattr,ExecuteCommand,(void
*)pArgumentObj);
if (0 =3D=3D nReturnCode)
{
TraceMessage << "--- LaunchThread() " << strInfo << " - THREAD
Successful" << endl;
}
else
{
TraceMessage << "--- LaunchThread(): Unable to launch the thread.
Enrichment Dropped. Error Code=3D " << nReturnCode << endl;
bErrorOccured=3D true;
}
}
else
{
TraceMessage << "<-- LaunchThread(): Failed to set
PTHREAD_CREATE_DETACHED attribute. Error Code=3D " << nReturnCode <<
endl;
bErrorOccured=3D true;
}
if (true =3D=3D bErrorOccured)
{
delete pArgs;
TraceMessage << "--- LaunchThread(): Decrementing the Command Count
because the Some Thread Error Occured." << endl;
TeMIPAlarmObjectUser::DecrementCommandCount();
m_Enrichment_Drop_Message=3D"LaunchThread(): Unable to launch the
thread-Enrichment Dropped";
m_IsEnrichmentDropped=3Dtrue;
TraceMessage << "--- " << m_Enrichment_Drop_Message << endl;
}
nReturnCode =3D pthread_attr_destroy(&tattr);
if ( 0 =3D=3D nReturnCode )
{
TraceMessage << "--- LaunchThread(): pthread_attr_destroy success"
<< endl;
}
else
{
TraceMessage << "--- LaunchThread(): pthread_attr_destroy Failed.
Error Code =3D " << nReturnCode << endl;
}
}
else
{
TraceMessage << "--- LaunchThread(): pthread_attr_init Failed. Error
Code =3D " << nReturnCode << endl;
}
TraceMessage << "<-- LaunchThread("<< bErrorOccured <<")" << endl;
return bErrorOccured;
}
// This function spawns the script with given arguments.
// This function will be invoked by Thread.
void* TeMIPAlarmObjectUser::ExecuteCommand(void *argList)
{
Argument *arg=3D (Argument *)argList;
RWCString cmdName=3Darg->commandName;
RWCString cmdArgs=3Darg->argList;
delete arg;
EXPSpawnedApplication* unixScript =3D new
EXPSpawnedApplication("CORR839_APPL",cmdName);
// Spawn synchronously
unixScript->setMode(EXP_K_SYNCHRONOUS);
unixScript->setArgList(cmdArgs);
unixScript->Spawn(false);
unixScript->Delete();
// Decrement Command Count
TeMIPAlarmObjectUser::DecrementCommandCount();
return NULL;
}
|
|
0
|
|
|
|
Reply
|
mugurvinay
|
2/25/2008 9:44:12 AM
|
|
mugurvinay@gmail.com wrote:
> 1. I have attached the functions, which I have used to invoke thread,
> and in turn to invoke the scripts
I'm not sure where you do that.
It would be helpful to have a tusc trace of your application:
tusc -o tusc.out -fpu executable parms ...
|
|
0
|
|
|
|
Reply
|
Dennis
|
2/27/2008 2:37:09 AM
|
|
|
3 Replies
128 Views
(page loaded in 0.054 seconds)
Similiar Articles: Execute Bash script using Cygwin - comp.soft-sys.matlabHello, I am trying to execute a bash script in Windows through the 'unix ... scripts on Windows « Duncan Smart's Weblog Invoking Cygwin’s Bash, passing it a shell script to ... access control and pool servers - comp.protocols.time.ntp ...I wrote a shell script, which I will post in a reply in this thread, which addresses some of the problems with pool servers and ... Of course, if you go through a SOHO ... Java Runtime.exec() and sudo. - comp.lang.java.programmer ...... run a unix script from the java applet that is runningunder tomcat.The problem ... the whole thread, as I'm in need of thereturncode of the script ... Shell Script for mount ... a unix script to send email notification when a sas batch job ...... is returned in $status for the C shell ... it fails, you could solve this problem by using the "||" conditional shell ... Previous by thread: Re: a unix script to send email ... What's a fast way to delete file by inode ? - comp.unix.shell ...... Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pro ... your strange-named file -0.1-1800 was (through ... Has anyone in this thread actually defined what ... gawk/Windows/cmd.exe/ARGV - comp.lang.awk... out what "the real question" is (aka, "What problem ... intent properly, I'll exit stage left for this thread. ... Windows/cmd.exe/ARGV - comp.lang.awk execute shell script ... Math operations on fields of different rows - comp.lang.awk ...... Shell Scripting Recipes: | My code in this post, if any, A Problem ... through my ISP nntp so I posted quite the same but when I did it there were only 3 posts in the thread! GAWK: A fix for "missing file is a fatal error" - comp.lang.awk ...And that's what makes this whole thread ... this is an interesting "yet another shell/script kludge" solution to the problem. ... probably piping the output of "pr" through ... efficiency in awk - comp.lang.awkC-shell. In our case, I think that if an awk script is more ... by ``-f script.awk --'' with no significant problems. ... arguments through awk - comp.unix.shell ... ... Running SAS on Ubuntu via wine - comp.soft-sys.sasSearching through wineHQ: http://appdb ... put the following line into a shell script: env WINEPREFIX="/home/user/.wine" wine "C ... Xemacs: syntax highlighting problem for ... problem in invoking shell script through a C++ threadproblem in invoking shell script through a C++ thread - HP UX . This is a discussion on problem in invoking shell script through a C++ thread - HP UX; Hi, I am facing ... Call One shell script from another shell script - LinuxQuestions.orgCall One shell script from another shell script ... use the advanced search, subscribe to threads and ... If you have any problems with the registration process ... 7/26/2012 8:48:47 PM
|