c, pass awk syntax as argument to execl

Posted by Skuja on Stack Overflow See other posts from Stack Overflow or by Skuja
Published on 2010-04-17T21:20:58Z Indexed on 2010/04/17 21:23 UTC
Read the original article Hit count: 192

Filed under:
|
|
|

I want to run following command in c to read systems cpu and memory usage:

ps aux|awk 'NR > 0 { cpu +=$3; ram+=$4 }; END {print cpu,ram}'

I am trying to pass it to execl command and after that read its output:

execl("/bin/ps", "/bin/ps", "aux|awk", "'NR > 0 { cpu +=$3; ram+=$4 }; END {print cpu,ram}'",(char *) 0);

but in terminal i am getting following error:

ERROR: Unsupported option (BSD syntax) I would like to know how to properly pass awk as argument to execl?

© Stack Overflow or respective owner

Related posts about c

    Related posts about linux