# Linux Kernel Module Cheat

### 23.7. QEMU monitor

The QEMU monitor is a magic terminal that allows you to send text commands to the QEMU VM itself: https://en.wikibooks.org/wiki/QEMU/Monitor

While QEMU is running, on another terminal, run:

    ./qemu-monitor

or send one command such as `info qtree` and quit the monitor:

    ./qemu-monitor info qtree

or equivalently:

    echo 'info qtree' | ./qemu-monitor

Source: qemu-monitor

`qemu-monitor` uses the `-monitor` QEMU command line option, which makes the monitor listen from a socket.

Alternatively, we can also enter the QEMU monitor from inside `-nographics` QEMU text mode with:

    Ctrl-A C

and go back to the terminal with:

    Ctrl-A C

- https://stackoverflow.com/questions/14165158/how-to-switch-to-qemu-monitor-console-when-running-with-curses

- https://superuser.com/questions/488263/how-to-switch-to-the-qemu-control-panel-with-nographics

When in graphic mode, we can do it from the GUI:

    Ctrl-Alt ?

where `?` is a digit `1`, or `2`, or, `3`, etc. depending on what else is available on the GUI: serial, parallel and frame buffer.

Finally, we can also access QEMU monitor commands directly from GDB step debug with the `monitor` command:

    ./run-gdb

then inside that shell:

    monitor info qtree

This way you can use both QEMU monitor and GDB commands to inspect the guest from inside a single shell! Pretty awesome.

In general, `./qemu-monitor` is the best option, as it:

- works on both modes

- allows to use the host Bash history to re-run one off commands

- allows you to search the output of commands on your host shell even when in graphic mode

Getting everything to work required careful choice of QEMU command line options:

- https://stackoverflow.com/questions/49716931/how-to-run-qemu-with-nographic-and-monitor-but-still-be-able-to-send-ctrlc-to/49751144#49751144

- https://unix.stackexchange.com/questions/167165/how-to-pass-ctrl-c-to-the-guest-when-running-qemu-with-nographic/436321#436321

- QEMU monitor from guest

- QEMU monitor from GDB