23

Occasionally emacs will hit 100% cpu usage. Obviously when this occurs there is an issue with a runaway process.

Just wondering if there is a way to view all running processes in emacs?

Kind of like unix htop, the interactive system process monitor & viewer... htop

orion
  • 805
  • 8
  • 16
  • 4
    `list-processes`? – npostavs Oct 24 '16 at 01:56
  • @npostavs thanks. list-processes is good. But I am wondering if there is something that provides more info on resources including memory and cpu usage – orion Oct 24 '16 at 02:02
  • 2
    The only thing I can think of is profiling: https://www.gnu.org/software/emacs/manual/html_node/elisp/Profiling.html – lawlist Oct 24 '16 at 02:40
  • 4
    lawlist is right. I don't believe you're looking for a *process* viewer at all (making `list-processes` or `proced` irrelevant). The only process you care about is the (single) emacs process itself, and you're trying to find out why it is utilising so much CPU time and/or memory. For that you need to use the emacs profiler. – phils Oct 24 '16 at 21:59

5 Answers5

24

The question was asked in 2016. Now in 2019, there exists M-x proced:

Mode for displaying system processes and sending signals to them.

Proced makes an Emacs buffer containing a listing of the current system processes. You can use the normal Emacs commands to move around in this buffer, and special Proced commands to operate on the processes listed. See proced-mode for getting started.

user1404316
  • 769
  • 5
  • 12
  • 2
    Note that you may want to enable `M-x proced-toggle-auto-update` on your `proced` buffer for a `top`-like behavior with automatic buffer update (every 5 seconds by default). – Pierre Thalamy Mar 12 '19 at 09:34
13

In addition to the other answers, the original poster may wish to consider using the built-in profiling feature: https://www.gnu.org/software/emacs/manual/html_node/elisp/Profiling.html

To begin profiling, type M-x profiler-start. You can choose to profile by processor usage, memory usage, or both. After doing some work, type M-x profiler-report to display a summary buffer for each resource that you chose to profile. The names of the report buffers include the times at which the reports were generated, so you can generate another report later on without erasing previous results. When you have finished profiling, type M-x profiler-stop (there is a small overhead associated with profiling).

See the link above to the manual for additional details regarding this feature.

lawlist
  • 18,826
  • 5
  • 37
  • 118
9

You may want to check list-processes:

list-processes is an interactive compiled Lisp function in ‘simple.el’.

(list-processes &optional QUERY-ONLY BUFFER)

Display a list of all processes that are Emacs sub-processes. If optional argument QUERY-ONLY is non-nil, only processes with the query-on-exit flag set are listed.
Any process listed as exited or signaled is actually eliminated after the listing is made.
Optional argument BUFFER specifies a buffer to use, instead of "*Process List*". The return value is always nil.

This function lists only processes that were launched by Emacs. To see other processes running on the system, use ‘list-system-processes’.

It seems to miss a lot of features you need, but with a bit coding you may get the desired results (if you do so, please send your patches upstream, I’d occasionally like to see this feature in Emacs.) That said, I couldn’t find any better ready-made candidates to your problem.

GergelyPolonkai
  • 748
  • 5
  • 12
8

Check out helm-top. It lists all the things you want, and has actions to send signals to the processes.

John Kitchin
  • 11,555
  • 1
  • 19
  • 41
7

I like htop and so I also use it in emacs. However the interactive part doesn't work this way.

(defun htop ()
  (interactive)
  (if (get-buffer "*htop*")
      (switch-to-buffer "*htop*")
    (ansi-term "/bin/bash" "htop")   
    (comint-send-string "*htop*" "htop\n")))
bertfred
  • 1,699
  • 1
  • 11
  • 23