Determine Status of Spawned Process

I use spawnl to spawn an copy process from /source to /destination.
the function returns the pid of the process since I use NO_WAIT
for the mode. Now, how would I be able to determine if the copy process
finished successfuly??

Before I used “system (“cp /source /destination”),” it returns -1 if system
can’t load a shell, otherwise the result of the cp function itself, 0 for
all input files copied successful, > 0 otherwise.


ran

Look at function “waitpid” which allows you to collect exit information on the
process with the pid returned from spawnl.

ran zhang wrote:

I use spawnl to spawn an copy process from /source to /destination.
the function returns the pid of the process since I use NO_WAIT
for the mode. Now, how would I be able to determine if the copy process
finished successfuly??

Before I used “system (“cp /source /destination”),” it returns -1 if system
can’t load a shell, otherwise the result of the cp function itself, 0 for
all input files copied successful, > 0 otherwise.

ran

Can u give me an exampe of how to use those MACROS after calling waitpid>
like how to get value of WIFEXIT…
Dean Douthat <ddouthat@faac.com> wrote in message
news:3BC718F3.E4F66968@faac.com

Look at function “waitpid” which allows you to collect exit information on
the
process with the pid returned from spawnl.

ran zhang wrote:

I use spawnl to spawn an copy process from /source to /destination.
the function returns the pid of the process since I use NO_WAIT
for the mode. Now, how would I be able to determine if the copy process
finished successfuly??

Before I used “system (“cp /source /destination”),” it returns -1 if
system
can’t load a shell, otherwise the result of the cp function itself, 0
for
all input files copied successful, > 0 otherwise.

ran

ran zhang <rzhang@vamcointernational.com> wrote:

Can u give me an exampe of how to use those MACROS after calling waitpid
like how to get value of WIFEXIT…

There’s an example using waitpid() in the fork() docs.

Barry

Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC718F3.E4F66968@faac.com> …
Look at function “waitpid” which allows you to collect exit information on
the
process with the pid returned from spawnl.

ran zhang wrote:

I use spawnl to spawn an copy process from /source to /destination.
the function returns the pid of the process since I use NO_WAIT
for the mode. Now, how would I be able to determine if the copy process
finished successfuly??

Before I used “system (“cp /source /destination”),” it returns -1 if
system
can’t load a shell, otherwise the result of the cp function itself, 0
for
all input files copied successful, > 0 otherwise.

ran

An extensive example is given under function “fork”.

ran zhang wrote:

Can u give me an exampe of how to use those MACROS after calling waitpid
like how to get value of WIFEXIT…
Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC718F3.E4F66968@faac.com> …
Look at function “waitpid” which allows you to collect exit information on
the
process with the pid returned from spawnl.

ran zhang wrote:

I use spawnl to spawn an copy process from /source to /destination.
the function returns the pid of the process since I use NO_WAIT
for the mode. Now, how would I be able to determine if the copy process
finished successfuly??

Before I used “system (“cp /source /destination”),” it returns -1 if
system
can’t load a shell, otherwise the result of the cp function itself, 0
for
all input files copied successful, > 0 otherwise.

ran

Dean:
You seem to know all the answer…
I got it to work. but those values don’t change wether my copy process
failed or not… failed as if one or more files didn’t get copied
if there a way to get the actual exit_status of the copy commands that my
copy process issues??

like system (“cp /source /destination”) does… it returns the exit_status of
the cp commands itself if the shel can be loaded… cp issues 0 when al
files copied correct, > 0 if one or more file didn’t get copied…
Dean Douthat <ddouthat@faac.com> wrote in message
news:3BC732E2.54297A28@faac.com

An extensive example is given under function “fork”.

ran zhang wrote:

Can u give me an exampe of how to use those MACROS after calling
waitpid
like how to get value of WIFEXIT…
Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC718F3.E4F66968@faac.com> …
Look at function “waitpid” which allows you to collect exit
information on
the
process with the pid returned from spawnl.

ran zhang wrote:

I use spawnl to spawn an copy process from /source to /destination.
the function returns the pid of the process since I use NO_WAIT
for the mode. Now, how would I be able to determine if the copy
process
finished successfuly??

Before I used “system (“cp /source /destination”),” it returns -1 if
system
can’t load a shell, otherwise the result of the cp function itself,
0
for
all input files copied successful, > 0 otherwise.

ran

Post your code.

ran zhang wrote:

Dean:
You seem to know all the answer…
I got it to work. but those values don’t change wether my copy process
failed or not… failed as if one or more files didn’t get copied
if there a way to get the actual exit_status of the copy commands that my
copy process issues??

like system (“cp /source /destination”) does… it returns the exit_status of
the cp commands itself if the shel can be loaded… cp issues 0 when al
files copied correct, > 0 if one or more file didn’t get copied…
Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC732E2.54297A28@faac.com> …
An extensive example is given under function “fork”.

ran zhang wrote:

Can u give me an exampe of how to use those MACROS after calling
waitpid
like how to get value of WIFEXIT…
Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC718F3.E4F66968@faac.com> …
Look at function “waitpid” which allows you to collect exit
information on
the
process with the pid returned from spawnl.

ran zhang wrote:

I use spawnl to spawn an copy process from /source to /destination.
the function returns the pid of the process since I use NO_WAIT
for the mode. Now, how would I be able to determine if the copy
process
finished successfuly??

Before I used “system (“cp /source /destination”),” it returns -1 if
system
can’t load a shell, otherwise the result of the cp function itself,
0
for
all input files copied successful, > 0 otherwise.

ran

For example… cp supposed to copy /.boot and /jack to /ran folder…
and /jack doesnt exit. so one of the cp commands failed,
how would i able to know in my code if al the cp commands successfully
finished…

thank you


Child = spawnl (P_NOWAIT, “/bin/cp”, “cp”, “-vcLR”, “/.boot”,"/jack",
“/ran”, NULL);
result = waitpid(Child, val, WNOHANG);
if (result == 0)
{ cout << "WIFEXITED == " << WIFEXITED(*val) << endl;
cout << "value == " << WEXITSTATUS(*val)<< endl;
cout << "Signaled " << WIFSIGNALED(*val) << endl;
cout << "signal value " << WTERMSIG(*val) << endl;
cout << "Stopped " << WIFSTOPPED(*val)<< endl;
cout << "WSTOPSIG " << WSTOPSIG(*val)<< endl;
}
Dean Douthat <ddouthat@faac.com> wrote in message
news:3BC73D7F.14A43996@faac.com

Post your code.

ran zhang wrote:

Dean:
You seem to know all the answer…
I got it to work. but those values don’t change wether my copy process
failed or not… failed as if one or more files didn’t get copied
if there a way to get the actual exit_status of the copy commands that
my
copy process issues??

like system (“cp /source /destination”) does… it returns the
exit_status of
the cp commands itself if the shel can be loaded… cp issues 0 when al
files copied correct, > 0 if one or more file didn’t get copied…
Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC732E2.54297A28@faac.com> …
An extensive example is given under function “fork”.

ran zhang wrote:

Can u give me an exampe of how to use those MACROS after calling
waitpid
like how to get value of WIFEXIT…
Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC718F3.E4F66968@faac.com> …
Look at function “waitpid” which allows you to collect exit
information on
the
process with the pid returned from spawnl.

ran zhang wrote:

I use spawnl to spawn an copy process from /source to
/destination.
the function returns the pid of the process since I use NO_WAIT
for the mode. Now, how would I be able to determine if the copy
process
finished successfuly??

Before I used “system (“cp /source /destination”),” it
returns -1 if
system
can’t load a shell, otherwise the result of the cp function
itself,
0
for
all input files copied successful, > 0 otherwise.

ran

Don’t use WNOHANG. Your cp hasn’t finished when you call waitpid so it will
return 0. This is documented under the WNOHANG option of waitpid.
Alternatively, loop over the waitpid or use P_WAIT in the spawnl.

ran zhang wrote:

For example… cp supposed to copy /.boot and /jack to /ran folder…
and /jack doesnt exit. so one of the cp commands failed,
how would i able to know in my code if al the cp commands successfully
finished…

thank you

Child = spawnl (P_NOWAIT, “/bin/cp”, “cp”, “-vcLR”, “/.boot”,"/jack",
“/ran”, NULL);
result = waitpid(Child, val, WNOHANG);
if (result == 0)
{ cout << "WIFEXITED == " << WIFEXITED(*val) << endl;
cout << "value == " << WEXITSTATUS(*val)<< endl;
cout << "Signaled " << WIFSIGNALED(*val) << endl;
cout << "signal value " << WTERMSIG(*val) << endl;
cout << "Stopped " << WIFSTOPPED(*val)<< endl;
cout << "WSTOPSIG " << WSTOPSIG(*val)<< endl;
}
Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC73D7F.14A43996@faac.com> …
Post your code.

ran zhang wrote:

Dean:
You seem to know all the answer…
I got it to work. but those values don’t change wether my copy process
failed or not… failed as if one or more files didn’t get copied
if there a way to get the actual exit_status of the copy commands that
my
copy process issues??

like system (“cp /source /destination”) does… it returns the
exit_status of
the cp commands itself if the shel can be loaded… cp issues 0 when al
files copied correct, > 0 if one or more file didn’t get copied…
Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC732E2.54297A28@faac.com> …
An extensive example is given under function “fork”.

ran zhang wrote:

Can u give me an exampe of how to use those MACROS after calling
waitpid
like how to get value of WIFEXIT…
Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC718F3.E4F66968@faac.com> …
Look at function “waitpid” which allows you to collect exit
information on
the
process with the pid returned from spawnl.

ran zhang wrote:

I use spawnl to spawn an copy process from /source to
/destination.
the function returns the pid of the process since I use NO_WAIT
for the mode. Now, how would I be able to determine if the copy
process
finished successfuly??

Before I used “system (“cp /source /destination”),” it
returns -1 if
system
can’t load a shell, otherwise the result of the cp function
itself,
0
for
all input files copied successful, > 0 otherwise.

ran

Stil… how can I determine wether my copy commands were successfully??
Dean Douthat <ddouthat@faac.com> wrote in message
news:3BC745A0.18B0FD3@faac.com

Don’t use WNOHANG. Your cp hasn’t finished when you call waitpid so it
will
return 0. This is documented under the WNOHANG option of waitpid.
Alternatively, loop over the waitpid or use P_WAIT in the spawnl.

ran zhang wrote:

For example… cp supposed to copy /.boot and /jack to /ran folder…
and /jack doesnt exit. so one of the cp commands failed,
how would i able to know in my code if al the cp commands successfully
finished…

thank you

Child = spawnl (P_NOWAIT, “/bin/cp”, “cp”, “-vcLR”, “/.boot”,"/jack",
“/ran”, NULL);
result = waitpid(Child, val, WNOHANG);
if (result == 0)
{ cout << "WIFEXITED == " << WIFEXITED(*val) << endl;
cout << "value == " << WEXITSTATUS(*val)<< endl;
cout << "Signaled " << WIFSIGNALED(*val) << endl;
cout << "signal value " << WTERMSIG(*val) << endl;
cout << "Stopped " << WIFSTOPPED(*val)<< endl;
cout << "WSTOPSIG " << WSTOPSIG(*val)<< endl;
}
Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC73D7F.14A43996@faac.com> …
Post your code.

ran zhang wrote:

Dean:
You seem to know all the answer…
I got it to work. but those values don’t change wether my copy
process
failed or not… failed as if one or more files didn’t get copied
if there a way to get the actual exit_status of the copy commands
that
my
copy process issues??

like system (“cp /source /destination”) does… it returns the
exit_status of
the cp commands itself if the shel can be loaded… cp issues 0 when
al
files copied correct, > 0 if one or more file didn’t get copied…
Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC732E2.54297A28@faac.com> …
An extensive example is given under function “fork”.

ran zhang wrote:

Can u give me an exampe of how to use those MACROS after calling
waitpid
like how to get value of WIFEXIT…
Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC718F3.E4F66968@faac.com> …
Look at function “waitpid” which allows you to collect exit
information on
the
process with the pid returned from spawnl.

ran zhang wrote:

I use spawnl to spawn an copy process from /source to
/destination.
the function returns the pid of the process since I use
NO_WAIT
for the mode. Now, how would I be able to determine if the
copy
process
finished successfuly??

Before I used “system (“cp /source /destination”),” it
returns -1 if
system
can’t load a shell, otherwise the result of the cp function
itself,
0
for
all input files copied successful, > 0 otherwise.


ran
\

Two methods shown in attachment.

ran zhang wrote:

Stil… how can I determine wether my copy commands were successfully??
Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC745A0.18B0FD3@faac.com> …
Don’t use WNOHANG. Your cp hasn’t finished when you call waitpid so it
will
return 0. This is documented under the WNOHANG option of waitpid.
Alternatively, loop over the waitpid or use P_WAIT in the spawnl.

ran zhang wrote:

For example… cp supposed to copy /.boot and /jack to /ran folder…
and /jack doesnt exit. so one of the cp commands failed,
how would i able to know in my code if al the cp commands successfully
finished…

thank you

Child = spawnl (P_NOWAIT, “/bin/cp”, “cp”, “-vcLR”, “/.boot”,"/jack",
“/ran”, NULL);
result = waitpid(Child, val, WNOHANG);
if (result == 0)
{ cout << "WIFEXITED == " << WIFEXITED(*val) << endl;
cout << "value == " << WEXITSTATUS(*val)<< endl;
cout << "Signaled " << WIFSIGNALED(*val) << endl;
cout << "signal value " << WTERMSIG(*val) << endl;
cout << "Stopped " << WIFSTOPPED(*val)<< endl;
cout << "WSTOPSIG " << WSTOPSIG(*val)<< endl;
}
Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC73D7F.14A43996@faac.com> …
Post your code.

ran zhang wrote:

Dean:
You seem to know all the answer…
I got it to work. but those values don’t change wether my copy
process
failed or not… failed as if one or more files didn’t get copied
if there a way to get the actual exit_status of the copy commands
that
my
copy process issues??

like system (“cp /source /destination”) does… it returns the
exit_status of
the cp commands itself if the shel can be loaded… cp issues 0 when
al
files copied correct, > 0 if one or more file didn’t get copied…
Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC732E2.54297A28@faac.com> …
An extensive example is given under function “fork”.

ran zhang wrote:

Can u give me an exampe of how to use those MACROS after calling
waitpid
like how to get value of WIFEXIT…
Dean Douthat <> ddouthat@faac.com> > wrote in message
news:> 3BC718F3.E4F66968@faac.com> …
Look at function “waitpid” which allows you to collect exit
information on
the
process with the pid returned from spawnl.

ran zhang wrote:

I use spawnl to spawn an copy process from /source to
/destination.
the function returns the pid of the process since I use
NO_WAIT
for the mode. Now, how would I be able to determine if the
copy
process
finished successfuly??

Before I used “system (“cp /source /destination”),” it
returns -1 if
system
can’t load a shell, otherwise the result of the cp function
itself,
0
for
all input files copied successful, > 0 otherwise.


ran
\