c, pass awk syntax as argument to execl
- by Skuja
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?