0

So I want to run Apache benchmark but while it's running, I need to run htop to see the memory and CPU usage. How can I do that? Putty (My ssh client) won't let me type in a command until ab is done running.

Ideas?

Chris S
  • 77,945
  • 11
  • 124
  • 216
Matthew
  • 1,859
  • 4
  • 22
  • 32

4 Answers4

1

You can do this in the same way that you would with a local shell, using job control. For example:

time ssh localhost 'bash -c "sleep 5 & sleep 6 &"'
... 0.00s user 0.01s system 0% cpu 6.187 total

Edit:
Oh, you just want to do it on from a terminal session. You just use job control by putting & after the command, for example: benchmark & and then htop. This makes the job run in the background. You can then see which jobs are running with the jobs command and bring it back to the foreground with fg %1 where 1 is the number of the job.

Kyle Brandt
  • 83,619
  • 74
  • 305
  • 448
  • Thanks. That's working (the & sign). Is there a way to stop ab from producing output (just running)? Otherwise, it just screws up the layout of htop. – Matthew Jun 10 '10 at 18:31
  • You probably just want to redirect the normal output (not error output) to a file or /dev/null with something like `ls -l >/dev/null & ` – Kyle Brandt Jun 10 '10 at 19:20
  • `bash -c` is not necessary; `ssh` already executes commands using the user's default shell. `ssh 'command1 & command2'` is sufficient. – user1686 Jun 10 '10 at 20:30
0

There are many solutions (run benchmark as background job), but the best solution is to use screen. It's "window manager" for console. You can create many windows, switch between them and even detach current session. It's a very powerful tool.

Michał Pipa
  • 101
  • 1
0

GNU Screen is a great application for running multiple processes (windows) inside of one SSH session. It must reside on the machine you connected to (server).

cdated
  • 199
  • 1
  • 1
  • 9
  • Doesn't have to be on the client machine. I log into servers and run screen from the server all the time. If fact, that is one of it's ideal uses because if you get disconnected everything keeps running and you can reattach it. – Kyle Brandt Jun 10 '10 at 18:29
  • Sorry, I wrote that too quickly (corrected). Screen is great for resuming sessions, it's a must for IRC. – cdated Jun 10 '10 at 19:52
0

Sometimes, especially for things that take some time to run, it might be better to simply open two SSH sessions. With the windows sitting side by side it's easy to monitor just what's happening. I tend to do this a lot when I'm tailing log files while testing things.

John Gardeniers
  • 27,458
  • 12
  • 55
  • 109