4

I've been stuck trying to do this for a while now, and I just cannot get it to work no matter what I try.

My C code looks like this:

char *const parmList[] = {"ps","-o pid",processID,NULL};
execvp("/bin/ps", parmList);

What am I doing wrong?

1
  • What is the type of processID? If it is a string that contains the PID, you'll be fine. If it is an integer, then you will have problems — it should be a string; all arguments to a command are strings. And, FWIW, the command as written would work on Mac OS X, but fails on Linux with error: improper format list (but on Linux, you could use ps -opid,ppid,time with no space between the -o and the list of columns to be printed, or with two separate arguments). Commented Sep 27, 2015 at 2:29

1 Answer 1

3

Not tested, I think you are executing

ps "-o pid,ppid,time" 3817

Try this:

char *const parmList[] = {"ps","-o","pid,ppid,time",processID,NULL};
execvp("/bin/ps", parmList);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.