> For the complete documentation index, see [llms.txt](https://www.learnros2.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.learnros2.com/ros/cookbook/how-to-properly-terminate-ros-and-gazebo.md).

# How to properly terminate ROS and Gazebo

ROS and Gazebo have many components running in the background. To properly terminate the program, one can use the `ps` command to collect all the related process IDs and then kill them manually. Here is a python utility code that collects the process IDs in the `ps` command outputs and execute the `kill -9` command.

```python
import sys
import subprocess

if __name__ == '__main__':
    result = []

    for _line in sys.stdin:
        line = _line.strip()
        if line:
            k = line.find(' ')
            while k < len(line) and line[k] == ' ':
                k += 1

            end_index = line.find(' ', k)
            result.append(line[k:end_index])

    command = ["kill", "-9"]
    command.extend(result[:-1])
    subprocess.run(command)
```

We can create an alias for this utility script, say, `alias kill-all="python <path-to-script>".` To usage the script, we can do

```bash
ps aux | grep -i ros | kill-all
ps aux | grep -i gazebo | kill-all
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.learnros2.com/ros/cookbook/how-to-properly-terminate-ros-and-gazebo.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
