If i got a piece of code:
system(“cp -vcLR /source /destination &”);
it spaws a shell and running it in the background. how can i get the PID of
it??
If i got a piece of code:
system(“cp -vcLR /source /destination &”);
it spaws a shell and running it in the background. how can i get the PID of
it??
ran zhang <rzhang@vamcointernational.com> wrote:
If i got a piece of code:
system(“cp -vcLR /source /destination &”);
it spaws a shell and running it in the background. how can i get the PID of
it??
You don’t.
If you need the pid of the “cp” command, don’t use system() – system()
starts a process (/bin/sh) which runs the command, then exits. You’re
starting two processes when you only need one.
Try:
pid = spawnl( P_NOWAIT, “/bin/cp”, “cp”, “-vcLR”, “/source”,
“/destination”, NULL );
QNX Training Services
dagibbs@qnx.com