AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-44254

John's questions

Martin Hope
John
Asked: 2024-10-09 00:28:04 +0800 CST

使用 GNU `time` 命令时“%CPU” 的含义是什么

  • 5

我怀疑我对运行 GNU 命令的输出的理解time是否正确。我现在想知道 CPU 百分比实际上表示什么。

在 macOS 上,我使用 homebrew 安装了 GNUtime实用程序gtime,并运行了一个非常简单的命令来检查其功能:

/usr/local/bin/gtime -f '\ntime: system %S user %U elapsed %e CPU %P \nstat: %x'  echo hi

hi

time: system 0.00 user 0.00 elapsed 0.00 CPU 100% 
stat: 0

使用相同的实用程序和更少的标志运行更简单的命令:

/usr/local/bin/gtime echo hi
hi
0.00user 0.00system 0:00.00elapsed 75%CPU (0avgtext+0avgdata 676maxresident)k
0inputs+0outputs (1major+420minor)pagefaults 0swaps

手册页指出

%S 系统(内核)时间(秒)
%P 此作业占用的 CPU 百分比
%U 用户时间(秒)

这是否意味着该命令效率低下,使用了 100% 的 CPU,还是意味着它非常高效,或者两者都不是。

我已经运行了一些其他更为复杂的 shell 脚本gtime,它们显示了一系列CPU 5%–CPU 9%这让我问了这个问题。

command-line
  • 1 个回答
  • 24 Views
Martin Hope
John
Asked: 2024-09-22 22:37:19 +0800 CST

如何使用“ssh”和“ps -U 501”查看远程服务器上运行的用户 501 进程

  • 4

我正在使用 从用户名为 John、ID 为 501 的 iMac 连接到用户名为 John、ID 为 501 的 MacMini ssh。

当我远程运行时,ps -U 501系统提示没有用户 ID 501。如果我在本地运行该命令,该命令将按预期返回 501 拥有的进程。我缺少哪些知识?

所有命令都从ssh会话运行

08:42:09.626 iMac191 ~ 
➜ ssh 169.254.1.1
([email protected]) Password:
Last login: Tue Sep 17 14:51:28 2024

john@MacMini ~ % whoami
501

john@MacMini ~ % id
uid=501 gid=20(staff) groups=20(staff),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),98(_lpadmin),398(com.apple.access_screensharing),704,703,716,702,706,705,701,100(_lpoperator)

john@MacMini ~ % ps -U 501
ps: No ruser name or ID matches '501'

john@MacMini ~ % su john
su: who are you?

john@MacMini ~ % ps -Af | grep 501
  501  2739     1   0 Tue02PM ??         0:00.59 /Applications/DiskWarrior.app/Contents/Helpers/DiskWarriorDaemon
  501 55207 55204   0  8:42AM ??         0:00.61 sshd: john@ttys002 
  501 55898     1   0  8:46AM ??         0:00.59 /System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow console
  501 55899     1   0  8:46AM ??         0:01.87 /usr/sbin/distnoted agent
  501 55937     1   0  8:47AM ??         0:03.81 /usr/sbin/cfprefsd agent
  501 55939     1   0  8:47AM ??         0:00.99 /usr/libexec/UserEventAgent (Aqua)

john@MacMini ~ % dscacheutil -q user | grep 501

john@MacMini ~ % login root
Password:
Login incorrect
login: login john
Login incorrect

man ps

关键字
ruid 真实用户 ID
ruser 用户名(来自 ruid)
uid 有效用户 ID

ssh
  • 1 个回答
  • 34 Views
Martin Hope
John
Asked: 2024-09-21 01:10:14 +0800 CST

打印多个 `lsof' 输出列,同时使用其中一列对唯一值进行排序和计数

  • 6

我想仅打印选定的lsof输出列
$1,$2,$3,$5,$8,$10
,并在打印所有初始输出列时使用uniq -c该列。PID

我在 macOS 上。我正在使用awk, sort,uniq -c

我将我的机器的 IP 地址存储在一个变量中:$ETH_IP

ETH_IP="192.168.10.191" && echo $ETH_IP
192.168.10.191

这是我当前的命令,带有一些格式及其结果:

(lsof -alP -Ts -i @"$ETH_IP" -s TCP:ESTABLISHED,LISTEN,CLOSE_WAIT +c0 |sed 's|\\x20|_|g' |awk '{print $1,$2,$3,$5,$8,$10}' |column -t)                                     
COMMAND                      PID    USER  TYPE  NODE
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
Mail                         668    501   IPv4  TCP   (ESTABLISHED)
GitHub_Desktop_Helper        1196   501   IPv4  TCP   (ESTABLISHED)
GitHub_Desktop_Helper        1196   501   IPv4  TCP   (ESTABLISHED)
com.apple.WebKit.Networking  12635  501   IPv4  TCP   (ESTABLISHED)
com.apple.WebKit.Networking  12635  501   IPv4  TCP   (ESTABLISHED)
com.apple.WebKit.Networking  12635  501   IPv4  TCP   (ESTABLISHED)
com.apple.WebKit.Networking  12635  501   IPv4  TCP   (ESTABLISHED)
com.apple.WebKit.Networking  12635  501   IPv4  TCP   (ESTABLISHED)
com.apple.WebKit.Networking  12635  501   IPv4  TCP   (ESTABLISHED)
com.apple.WebKit.Networking  12635  501   IPv4  TCP   (ESTABLISHED)
com.apple.WebKit.Networking  12635  501   IPv4  TCP   (ESTABLISHED)
com.apple.WebKit.Networking  12635  501   IPv4  TCP   (ESTABLISHED)
com.apple.WebKit.Networking  12635  501   IPv4  TCP   (ESTABLISHED)
com.apple.WebKit.Networking  12635  501   IPv4  TCP   (ESTABLISHED)
com.apple.WebKit.Networking  12635  501   IPv4  TCP   (ESTABLISHED)
com.apple.WebKit.Networking  12635  501   IPv4  TCP   (ESTABLISHED)
com.apple.WebKit.Networking  12635  501   IPv4  TCP   (ESTABLISHED)
Dropbox                      74706  501   IPv4  TCP   (ESTABLISHED)
Dropbox                      74706  501   IPv4  TCP   (ESTABLISHED)
Dropbox                      74706  501   IPv4  TCP   (ESTABLISHED)
DropboxFileProvider          74707  501   IPv4  TCP   (ESTABLISHED)
DropboxFileProvider          74707  501   IPv4  TCP   (ESTABLISHED)
DropboxFileProvider          74707  501   IPv4  TCP   (ESTABLISHED)

我想使用类似 的内容| sort | uniq -c | sort -n。
使用第 2 列 (PID) 中的值uniq。
使用awk并保留如上所示的多列格式。
因此,每个进程只有一个列表,行前面列出了原始行的数量。

我正在寻找的模型。

COMMAND                         PID    USER  TYPE  NODE  
18 Mail                         668    501   IPv4  TCP                (ESTABLISHED)
 2 GitHub_Desktop_Helper        1196   501   IPv4  TCP                (ESTABLISHED)
 2 Code_Helper                  1493   501   IPv4  TCP                (ESTABLISHED)
14 com.apple.WebKit.Networking  12635  501   IPv4  TCP                (ESTABLISHED)
 3 Dropbox                      74706  501   IPv4  TCP                (ESTABLISHED)
 2 DropboxFileProvider          74707  501   IPv4  TCP                (ESTABLISHED)    

我面临的问题是 HEADER 行也被计算在内uniq -c

(lsof -alP -Ts -i @"$ETH_IP" -s TCP:ESTABLISHED,LISTEN,CLOSE_WAIT +c0 |sed 's|\\x20|_|g' |awk '{print $1,$2,$3,$5,$8,$10}' |column -t) | sort -k 2,2 | uniq -c | sort  -n -k 3,3
   1 COMMAND                      PID    USER  TYPE  NODE
   3 accountsd                    667    501   IPv4  TCP   (ESTABLISHED)
  16 Mail                         668    501   IPv4  TCP   (ESTABLISHED)
   2 GitHub_Desktop_Helper        1196   501   IPv4  TCP   (ESTABLISHED)
  12 com.apple.WebKit.Networking  12635  501   IPv4  TCP   (ESTABLISHED)
   2 Dropbox                      74706  501   IPv4  TCP   (ESTABLISHED)
   2 DropboxFileProvider          74707  501   IPv4  TCP   (ESTABLISHED)

这个想法来自于这个命令及其输出。

lsof -alP -Ts -i @"$ETH_IP"  -s TCP:ESTABLISHED,LISTEN,CLOSE_WAIT  +c0 | awk 'NR>2{print $1}' | sort | uniq -c | sort -n
   1 CloudTelemetryService
   1 cloudd
   2 Dropbox
   2 DropboxFileProvider
   2 GitHub\x20Desktop\x20Helper
  14 com.apple.WebKit.Networking
  17 Mail

awk
  • 1 个回答
  • 24 Views
Martin Hope
John
Asked: 2024-09-16 02:09:32 +0800 CST

if then 语句仅对匹配字符串的第一个实例起作用

  • 5

我在这里缺少一些知识,也没有合适的语言来描述(抱歉)。这是我的命令,它只在找到“$WARN”中的匹配项时返回第一个实例

echo "$WARN"

(W) 2024-08-30T08:08:52 - Restart is required to toggle support
(W) 2024-08-30T09:59:30 - Failed to download RSS feed at 'https://aaa'. Reason: The connection to the remote server timed out
(W) 2024-08-30T10:00:30 - Failed to download RSS feed at 'https://bbb'. Reason: The connection to the remote server timed out
(W) 2024-08-30T10:00:30 - Failed to download RSS feed at 'https://ccc'. Reason: The connection to the remote server timed out
(W) 2024-09-13T08:59:44 - Failed to download RSS feed at 'http://xxx'. Reason: The remote server refused the connection
(W) 2024-09-13T08:59:44 - Failed to download RSS feed at 'http://yyy'. Reason: The remote server refused the connection
(W) 2024-09-13T08:59:44 - Failed to download RSS feed at 'http://zzz'. Reason: The remote server refused the connection

WARN=$(
  if [[ "$WARN" == *Failed* ]]
  then
  printf '%s' "${WARN//''\'*''\'\./...}"
  fi
)

echo "$WARN"

(W) 2024-08-30T08:08:52 - Restart is required to toggle support
(W) 2024-08-30T09:59:30 - Failed to download RSS feed at ... Reason: The connection to the remote server timed out

预期输出:唯一行和与“失败”匹配的行被修改以删除单引号内的所有内容,包括引号本身。

(W) 2024-08-30T08:08:52 - Restart is required to toggle support
(W) 2024-08-30T09:59:30 - Failed to download RSS feed at ... Reason: The connection to the remote server timed out
(W) 2024-09-13T08:59:44 - Failed to download RSS feed at ... Reason: The remote server refused the connection

实际输出:为什么省略了第二行的考虑,即只有包含的第一个匹配的行Failed被执行并返回。

echo "$WARN"

(W) 2024-08-30T08:08:52 - Restart is required to toggle support
(W) 2024-08-30T09:59:30 - Failed to download RSS feed at ... Reason: The connection to the remote server timed out

如果我对输入进行排序,则将其反转,第二次匹配的出现Failed会被省略。

echo "$WARN"

(W) 2024-09-13T08:59:44 - Failed to download RSS feed at ... Reason: The remote server refused the connection
(W) 2024-08-30T08:08:52 - Restart is required to toggle support

我不想匹配字符串的末尾。

我第二次创建变量 $WARN 时,用新内容替换它。

bash
  • 1 个回答
  • 21 Views
Martin Hope
John
Asked: 2023-11-08 02:36:58 +0800 CST

当没有公钥时如何验证软件包安装程序

  • 6

我正准备安装privoxy,并且希望在他们的网站、SourceForge 或密钥服务器上的某个位置找到 privoxy 公钥。我找不到它。我发现的所有 gpg 教程都表明这是验证文件真实性的重要组成部分。

我已经下载了软件包安装程序和随附.asc文件,但显然没有开发人员的公钥,我无法验证它。

Privoxy 3.0.34 64 bit.pkg.asc
Privoxy 3.0.34 64 bit.pkg

gpg --verify /Users/john/Downloads/Privoxy\ 3.0.34\ 64\ bit.pkg.asc /Users/john/Downloads/Privoxy\ 3.0.34\ 64\ bit.pkg 
gpg: Signature made Sun Feb  5 14:27:04 2023 CST
gpg:                using RSA key A90A85C1159F009DC3CDAE76451009FAB9D8A252
gpg: Can't check signature: No public key

gpg --keyserver https://pgp.mit.edu/ --search-keys A90A85C1159F009DC3CDAE76451009FAB9D8A252
gpg: data source: https://pgp.mit.edu:443
gpg: key "A90A85C1159F009DC3CDAE76451009FAB9D8A252" not found on keyserver
gpg: keyserver search failed: Not found

我假设我在这里有错。.asc如果没有一种方法可以使用包文件来验证包,那么开发人员为什么要费尽心思发布包文件呢?

看看这篇旧文章,它表明公钥应该可用并且比哈希值更有用。

我将不胜感激任何有关此的信息/建议/帮助。

谢谢

尝试了额外的操作

gpg --import Privoxy\ 3.0.34\ 64\ bit.pkg.asc                       
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
gnupg
  • 1 个回答
  • 30 Views
Martin Hope
John
Asked: 2022-08-09 12:58:53 +0800 CST

如何获取 mp4 文件或流的前 4096 个字节的 SHA1?

  • 5

我正在尝试使用命令行工具来匹配 Plex.app 为电影文件计算的哈希值(显然,它是电影第一个块(4k)而不是整个电影的 SHA1 哈希)。

我尝试使用以下命令使用命令行工具获取哈希,但不出所料,这两个哈希不匹配。

file="/path/to/mp4"
dd bs=4k count=1 if="$file" | openssl sha1
1+0 records in
1+0 records out
4096 bytes transferred in 0.000012 secs (341333333 bytes/sec)
7785d5d6d611a27ac03dfdff8a2c89e9ffeffa3b
file="/path/to/mp4"
head -c 4096< "$file" | openssl sha1
7785d5d6d611a27ac03dfdff8a2c89e9ffeffa3b

使用ffprobe我意识到该 mp4 文件开头的大部分数据是编码设置而不是视频流。让我觉得无论 Plex 使用什么进程,它都可能避免文件的编码设置,因为它们可能完全相同。

请记住,这些值与尝试复制其哈希计算的适当工具不匹配的原因可能有很多。

ffmpeg openssl
  • 2 个回答
  • 89 Views
Martin Hope
John
Asked: 2022-01-31 18:44:13 +0800 CST

如何在 macOS 中更新“pgrep”以解决已知的“pgrep -d”问题

  • 6

pgrep在macOS Catalina 中安装的(2010 年 2 月 11 日)版本中,设置分隔符时存在错误。分隔符应该只打印在每个进程 ID 之间,但它也被打印为行终止符。

这在FreeBSD Bugzilla 错误号 203744中有记录。

有没有办法为 macOS 下载更新版本的 pgrep?

我也无法在我的机器上获得 pgrep 的版本。使用pgrep -V会导致错误。使用what给了我这个:

what /usr/bin/pgrep
/usr/bin/pgrep
    PROGRAM:pkill  PROJECT:adv_cmds-174.0.1
macos command-line
  • 1 个回答
  • 135 Views
Martin Hope
John
Asked: 2020-08-24 13:24:57 +0800 CST

AppleScript 使用 Safari 窗口 ID 创建新标签

  • 6

我有一个 AppleScript,它创建一个新的 Safari 文档,然后使用重复循环在该窗口中打开多个 URL。我希望脚本继续使用同一个窗口,即使它不是最前面的窗口。

(问题是如果用户将焦点转移到另一个 Safari 窗口,此脚本将在最前面的窗口中打开 URL,而不是之前创建的窗口。)

如果可能的话,我想通过使用解决这个问题,window id但需要一些关于脚本的帮助。

为此,我创建了以下内容,但我再次认为可能存在问题。我宁愿不使用 id,front window因为用户可能会在不合时宜的时间更改前窗,并且脚本会提取错误的窗口 ID。

tell application "Safari"
    make new document -- after this what if user changes focus
    set win_ID to id of front window of application "Safari"
end tell

我宁愿使用类似的东西

set win_ID to window id of (make new document)

即使使用上述方法,我也无法通过使用它的窗口 ID 在窗口中打开 URL,并且还需要有关该脚本的帮助。

它的功能是这样的:

tell application "Safari"
    open location "https://apple.com" in a new tab in window id xxxx
end tell
safari applescript
  • 2 个回答
  • 680 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve