ID:1977218
 
(See the best response by NullQuery.)
Code:


Hi, i gor some questions about using linux in DM:
1. How i can check my cpu ussage?(the whole cpu ussage).
2. How i can run bash script?
3. Is there a way, to show cpu ussage, made by xx procces, daemon?

Best response
If you host your game in trusted mode (using the "--trusted" flag in DreamDaemon) you'll be able to call the shell() proc from within your game.

This proc allows you to execute any arbitrary command that you would normally be able to type in the Linux terminal. IIRC the response from the command is returned as the result, though the reference implies the exit code is used instead (can someone elaborate? I don't have a test environment at the moment).

Either way you'll be able to get it to work. If shell() doesn't give the response but an exit code instead you can write the result of the command to a file and use the file2text() proc to read that file.

Taking this into account, answering your questions is just a matter of providing the Linux commands you need to get the result you want.
  1. world.cpu is intended to be used as an indicator of how much CPU your world uses. If this is not enough, you'll have to use the method you're asking for in question 3.
  2. You can call any bash script using the shell() command. Just provide the path to the script to execute. IIRC you may use relative paths such as shell("./myscript.sh") to execute "myscript.sh" in the current folder.
  3. A good place to start would be the following command:
    ps -eo pcpu,pid,args --no-headers | grep DreamDaemon | grep -v grep
    This should list the CPU usage of all running DreamDaemon processes and their PID's.

    Additionally you should be able to list only the current DreamDaemon process by executing the following command from shell():
    ps -eo pcpu,pid,args --no-headers | grep $$ | grep -v grep
    (The $$ variable is converted to the PID of the process you're executing the command from.)
I hope this helps! :)
You're right shell won't return a result, you need to pipe it to a file first.
:O thx you alot guys :-}