Go中当前正在运行的进程的列表 [英] List of currently running process in Go

查看:870
本文介绍了Go中当前正在运行的进程的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获得Go中当前正在运行的进程列表?



OS包提供了一些函数: http://golang.org/pkg/os/
,但没有提供任何内容查看正在运行的进程列表。

解决方案

标准库中没有这样的函数,很可能永远都不会有。



在大多数情况下,程序不需要进程列表。 Go程序通常希望等待一个或更少个进程,而不是所有进程。进程PID通常通过其他方式获得,而不是搜索所有进程的列表。



如果你在Linux上,进程列表可以通过阅读 / proc 目录。请参阅 Linux API以列出正在运行的进程

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中当前正在运行的进程的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆