如何获得*nix命令" ps " 的全宽结果?
我知道我们可以指定类似的东西,--cols 1000但无论如何我可以在列中打印出所有内容吗?
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main() {
int res = system("ps ax -o pid -o command | grep sudoku | grep gnome > /dev/null");
printf("res = %d \n", res);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我想sudoku通过检查system()(或任何其他调用)的返回代码来查看是否正在运行.我不想在任何地方打印任何输出.
system()即使在查看手册页后,我也不太了解返回代码
无论是否sudoku正在运行,我明白了res = 0.
假设我有一个如下所示的ps命令:
ps -Ao args:80,time,user --sort time
Run Code Online (Sandbox Code Playgroud)
它会给我一个"空格"分隔的行集.一行可能看起来像这样
paulnath -bash 00:00:00
Run Code Online (Sandbox Code Playgroud)
我想说服ps用逗号分隔(或者甚至是标签!),这样它就可以被其他语言自动处理.请注意,args中可能包含空格,因此,按字段调整本身不会起作用.
我想从我的流程中获取pid.我这样做,ps aux | cut -d ' ' -f 2但我注意到有时它得到了pid,有时却没有:
[user@ip ~]$ ps aux
user 2049 0.5 10.4 6059216 1623520 ? Sl date 8:48 process
user 12290 0.3 6.9 5881568 1086244 ? Sl date 2:30
[user@ip ~]$ ps aux | cut -d ' ' -f 2
12290
[user@ip ~]$ ps aux | cut -d ' ' -f 3
2049
Run Code Online (Sandbox Code Playgroud)
请注意,第一个cut命令是将它管道,2而第二个命令是将它管道3.如何从这些中选择PID而无需知道要使用哪个号码(2或3)?
有人可以告诉我这些之间的区别以及为什么它拿起一个而不是另一个?
我正在捕获输出ps aux:
current_processes=`ps aux | grep "tempdir" | tail -3`
Run Code Online (Sandbox Code Playgroud)
当我回应它时,它看起来像这样
echo $current_processes
19984 10089 17784
Run Code Online (Sandbox Code Playgroud)
当我echo加双引号时,它看起来像这样:
echo "$current_processes"
19984
10089
17784
Run Code Online (Sandbox Code Playgroud)
当我使用双引号但没有双引号时,为什么将它们放在新行上?
如何从Unix获取所有正在运行的进程的进程列表,包含命令/进程名称和进程ID,因此我可以过滤和终止进程.
它是关于linux的procps包,实用程序ps.
它可以打印每个进程(线程)的最后使用的CPU数量吗?
更新:不是CPU时间(10秒),而是CPU NUMBER(CPU0,CPU5,CPU123)
我知道[1]。通过几行代码,我只想从CPU使用率最高的前n个进程中提取当前的CPU使用率。或多或少都是前5排的顶部。使用github.com/shirou/gopsutil/process这很简单:
// file: gotop.go
package main
import (
"log"
"time"
"sort"
"github.com/shirou/gopsutil/process"
)
type ProcInfo struct{
Name string
Usage float64
}
type ByUsage []ProcInfo
func (a ByUsage) Len() int { return len(a) }
func (a ByUsage) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByUsage) Less(i, j int) bool {
return a[i].Usage > a[j].Usage
}
func main() {
for {
processes, _ := process.Processes()
var procinfos []ProcInfo
for _, p …Run Code Online (Sandbox Code Playgroud) 用C编写的多线程进程几乎耗尽了所有的系统内存。为了找出消耗大部分内存的线程,我创建了一个核心文件gcore [pid]来检查每个线程的内存使用情况,但我找不到方法来做到这一点。
ps -eLFlm带有-H选项的 top 命令显示总内存消耗,但不是每个线程。
有什么有用的提示可以解决问题吗?
操作系统:Centos6
我正在尝试使用 docker ps 和 json format 命令生成如下所示的输出
{"Names":"name"}
docker ps --format '{{json .Names}}'
Run Code Online (Sandbox Code Playgroud)
输出{"name"}没有标签。
docker ps --format '{{json .}}'提供带有标签的所有容器信息,但我不想要所有内容。
最好基于下面的所有占位符名称,我希望得到如下所示的输出,其中包含按我选择的顺序选择的字段:
{"ID":"Container ID", "Image":"Image ID", "Names":"name"}
Run Code Online (Sandbox Code Playgroud)
Placeholder Description
.ID Container ID
.Image Image ID
.Command Quoted command
.CreatedAt Time when the container was created.
.RunningFor Elapsed time since the container was started.
.Ports Exposed ports.
.Status Container status.
.Size Container disk size.
.Names Container names.
.Labels All labels assigned to the container.
.Label Value of a specific label …Run Code Online (Sandbox Code Playgroud)