> For the complete documentation index, see [llms.txt](https://yeasy.gitbook.io/mininet_book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yeasy.gitbook.io/mininet_book/qi-ta-mo-kuai/clean.md).

# mininet.clean 模块

提供对执行 Mininet 后的清理工作，主要包括 cleanup() 函数，该函数实际上调用了 sh() 函数。

cleanup() 函数主要包括清除僵尸进程，临时文件，X11 tunnel，额外的内核态 datapath，ovs datapath，ip link 等。

实现过程主要是通过调用 subprocess 模块（主要用于执行外部命令和程序）中的 Popen 类中方法来对进程发送指令。

```
def sh( cmd ):
    "Print a command and send it to the shell"
    info( cmd + '\n' )
    return Popen( [ '/bin/sh', '-c', cmd ], stdout=PIPE ).communicate()[ 0 ]
```

communicate() 是 Popen 对象的一个方法，该方法会阻塞父进程，直到子进程完成。 通过指定 stdout=PIPE，可以通过 stdout 获取程序的返回值。通过列表传入要执行的命令和参数。


---

# 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, and the optional `goal` query parameter:

```
GET https://yeasy.gitbook.io/mininet_book/qi-ta-mo-kuai/clean.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
