My programme is named ‘berkut’. I want to get the CPU and memory usage of this programme, so I use ‘top’ command together with ‘pidof’ like following:
[root#]pidof berkut
xxx
[root#]top -p xxx
(top screen is shown here)
Is there a shortcut way to combine these 2 commands so that I can call it directly with the system call: system(“…”); of C++?
It doesn’t matter how long the string passed into ‘system’ call, but should not be extremely long. I manually run the programme, so I’m quite sure that there is only 1 PID for it. This means when calling ‘pidof’, the ‘xxx’ is the only 1 PID found.
You can do the following:
The expression
$(<command>)tellsbashto evaluate<command>first. It is the same of using`<command>`as pointed by @tozka.