每次我运行ps时,它都返回通常的PID和CMD,但是

时间:2017-07-11 16:25:16

标签: bash command-line terminal ps

在我读过的每本书中,它永远不会像这样回归:

var weekGroups = projects
    .Select(p => new 
    { 
        Project = p
    })
    .GroupBy(x => x.Project.DateStart.StartOfWeek(DayOfWeek.Monday))
    .Select((g, i) => new 
    { 
        WeekGroup = g, 
        WeekNum = i + 1
    });

foreach (var projGroup in weekGroups)
{
    Console.WriteLine("Week " + projGroup.WeekNum);
    foreach(var proj in projGroup.WeekGroup)
        Console.WriteLine("{0} {1} {2}", 
            proj.Project.Name, 
            proj.Project.DateStart.ToString("d"), 
            proj.Project.ID);
} 

我的PID CMD 2748 -bash 8114 awk 7900 -bash 返回的是什么。 ps-之前是否正常?我只见过bash,从来没有见过2290 bash。琐碎的问题,但我认为这是不正常的。谢谢,抱歉这个愚蠢的问题。

1 个答案:

答案 0 :(得分:1)

这意味着登录shell。看看man bash

A login shell is one whose first character of argument zero is a -, or one started with the --login option.

如果你运行cat /proc/2748/cmdline,你会看到那里的连字符。这就是ps从中获取它的地方。 -f会查看/proc/[pid]/cmdline,而默认情况下会查看/proc/[pid]/comm

tom@riki:~$ ps
  PID TTY          TIME CMD
 9230 pts/2    00:00:00 bash
 9429 pts/2    00:00:00 ps

tom@riki:~$ ps -f
UID        PID  PPID  C STIME TTY          TIME CMD
tom       9230  9229  0 17:39 pts/2    00:00:00 -bash
tom       9427  9230  0 18:22 pts/2    00:00:00 ps -f

tom@riki:~$ cat /proc/9230/comm
bash

tom@riki:~$ cat /proc/9230/cmdline
-bash