Merged
Conversation
Owner
|
👍 问题收到 @xiongchen2012 我看看你实现的解法 |
Owner
问题测试分析找了一台机器测试超过8个字符的用户名: $ ps -eo comm,user,ruser,uid
COMMAND USER RUSER UID
init root root 0
sshd root root 0
crond root root 0
...
java admin admin 662
...
bash 59504 59504 59504
ps 59504 59504 59504
...
$ ps -eo comm,user -o ruser=${USER} -o uid
COMMAND USER username_long UID
init root root 0
sshd root root 0
crond root root 0
java admin admin 662
bash 59504 username_long 59504
ps 59504 username_long 59504解释说明:
- ps -Leo pid,lwp,user,comm,pcpu --no-headers | {
+ ps -Leo pid,lwp -o ruser=${USER} -o comm,pcpu --no-headers | {按你上面的修改,如果有个用户比 你当前用户名 还长的话,还是会有截断的bug。 解法确定了是列宽导致截断的问题,看了一下 -o format
User-defined format. format is a single argument in the form of a
blank-separated or comma-separated list, which offers a way to specify
individual output columns. The recognized keywords are described in the
STANDARD FORMAT SPECIFIERS section below. Headers may be renamed (ps -o
pid,ruser=RealUser -o comm=Command) as desired. If all column headers are
empty (ps -o pid= -o comm=) then the header line will not be output.
Column width will increase as needed for wide headers; this may be used to
widen up columns such as WCHAN (ps -o pid,wchan=WIDE-WCHAN-COLUMN -o comm).
Explicit width control (ps opid,wchan:42,cmd) is offered too.
...即这一句: 验证$ ps -eo comm,user:20,ruser,uid
COMMAND USER RUSER UID
init root root 0
sshd root root 0
crond root root 0
...
java admin admin 662
...
bash username_long 59504 59504
ps username_long 59504 59504
...实现修改- ps -Leo pid,lwp,user,comm,pcpu --no-headers | {
+ ps -Leo pid,lwp,user:80,comm,pcpu --no-headers | {假定没有超过80字符的用户名了,这个工程实现上实际上足够了 😸 Done! @xiongchen2012 |
Owner
|
@xiongchen2012 PR已经合并 另外,实现优化 也提交了, 见 f817da7 @xiongchen2012 麻烦测试一下,在你的环境是不是也是OK的?? 💓 ❤️ Thanks for your bug submission and implementation commit! ❤️ |
oldratlee
pushed a commit
that referenced
this pull request
Nov 1, 2017
Merge pull request #62 from xiongchen2012/master
oldratlee
added a commit
that referenced
this pull request
Nov 1, 2017
oldratlee
added a commit
that referenced
this pull request
Nov 1, 2017
oldratlee
added a commit
that referenced
this pull request
Nov 1, 2017
Contributor
Author
|
Nice work~ |
Owner
|
@xiongchen2012 方便在你的环境测试一下?结果如何? |
Contributor
Author
|
已经OK了,谢谢。 |
Owner
Owner
|
修改了实现,没有 修改参见 808a2e3 :
|
oldratlee
pushed a commit
that referenced
this pull request
Nov 28, 2017
Merge pull request #62 from xiongchen2012/master
oldratlee
added a commit
that referenced
this pull request
Nov 28, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ps -o user参数,当用户超过8个时,超过部分会显示为+号。例如:whoami=njiclscy-7
执行脚本提示:
这个问题导致脚本无法执行。但实际上启动Java进程的用户确实是
njiclscy-7PR的修改方法是取出当前用户名,使用
ruser选项输出用户名。