system() raising SIGTERM

I'm using the system() call to run the ps command on my PID and redirect the output to a file.
"ps -fp <pid> > /tmp/filename.<pid>

The system() call returns 0, but this always raises SIGTERM.

Anyone know why this signal is being raised? Or how I can avoid it?
I'm not sure why you're getting a SIGTERM, a SIGCHLD yes.

Using system() is fraught with problems.

It launches a shell (usually bourne) to run the command you specify. The return value you get from system() is the shells exit value and bears no relation to the command that it ran. The shell should catch any signals that your command generated, and you program should get the SIGCHLD from the shell terminating.

If you launch a command to run in the background, system() could well return before the command finishes though I can see your not doing this.

I suspect your SIGTERM is coming from somewhere else.

Just a point, but have you considered using the proc file system instead of ps on the command line? It's very powerful and easy to use.
Topic archived. No new replies allowed.