问题描述
我如何获得Go中当前正在运行的进程列表?
OS包提供了一些函数:
,但没有提供任何内容查看正在运行的进程列表。
标准库中没有这样的函数,很可能永远都不会有。
在大多数情况下,程序不需要进程列表。 Go程序通常希望等待一个或更少个进程,而不是所有进程。进程PID通常通过其他方式获得,而不是搜索所有进程的列表。
如果你在Linux上,进程列表可以通过阅读 / proc
目录。请参阅
How can I get the list of currently running processes in Go?
The OS package provides some functions: http://golang.org/pkg/os/but doesn't give anything to see the list of running processes.
There is no such function in the standard library and most likely never will be.
In most cases, the list of processes isn't required by programs. Go programs usually want to wait for a single or a smaller number of processes, not for all processes. PIDs of processes are usually obtained by other means than searching the list of all processes.
If you are on Linux, the list of processes can be obtained by reading contents of /proc
directory. See question Linux API to list running processes?
这篇关于Go中当前正在运行的进程的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!