Определить, в какой группе (ах) находится запущенный процесс?

Как показывают другие ответы, cat не очень подходящий инструмент для этого.

Как я сказал в своем комментарии, ваш вопрос некорректно определен, потому что вы не указываете, как команда должна распознавать абзацы. Один из способов сделать это - сделать это с отступом в первой строке. { {1}} nl -bp "^" - это команда, которая довольно хорошо подходит для обработки такой формы ввода:

$ cat text1
Some Verse
 The quick brown fox
jumps over the lazy dog.
 The Owl and the Pussy-cat went to sea
In a beautiful pea green boat,

$ nl -bp"^ " text1
       Some Verse
     1   The quick brown fox
       jumps over the lazy dog.
     2   The Owl and the Pussy-cat went to sea
       In a beautiful pea green boat,

Другой способ - использовать пустые строки в качестве разделителей. awk довольно хорошо справляется с подобными вещами.

$ cat num_pp
#!/bin/sh
awk 'BEGIN    {start=1}
     /^$/     {start=1}
    {
        if ($0 != ""  &&  start) {
                print ++ppnum, $0
                start=0
        } else print
    }' "$@"

$ cat text2
Some Verse
 The quick brown fox
jumps over the lazy dog.

The Owl and the Pussy-cat went to sea
 In a beautiful pea green boat,

$ ./num_pp text2
1 Some Verse
 The quick brown fox
jumps over the lazy dog.

2 The Owl and the Pussy-cat went to sea
 In a beautiful pea green boat,
6
17.05.2018, 23:42
4 ответа

La lista de grupos se proporciona bajo Groupsen /proc/ /status; por ejemplo,

$ grep '^Groups' /proc/$$/status
Groups: 4 24 27 30 46 110 115 116 1000

El grupo primario se da enGid:

$ grep '^Gid' /proc/$$/status
Gid:    1000    1000    1000    1000

pstambién es capaz de mostrar los grupos de un proceso, como indican las otras respuestas.

10
27.01.2020, 20:22

En un sistema UNIX derivado de SVr4, puede llamar a:

pcred <prcess-id>

Tenga en cuenta que el oficial procfsno es ASCII sino binario.

-3
27.01.2020, 20:22

Para la identificación de grupo efectiva, la identificación de grupo real y las identificaciones de grupo suplementarias (como se usa para el control de acceso):

ps -o gid,rgid,supgid -p "$pid"

gidy rgidson ​​bastante portátiles, supgidmenos que (los 3 estarían disponibles con el psde procps como se encuentra típicamente en los sistemas basados ​​​​en Linux -).

group, rgroupy supgrpse pueden usar para traducir ID de grupo a nombres de grupo, pero tenga en cuenta que para los ID de grupo que tienen varios nombres de grupo correspondientes, solo se mostrará uno de ellos (igual que para ls -lvs ls -no cualquier cosa que trate con nombres de usuarios o grupos basados ​​en ids ).

Para el ID de grupo de proceso (como se usa para el control de trabajo de terminal):

ps -o pgid -p "$pid"

Para almacenarlo en una variable:

pgid=$(($(ps -o pgid= -p "$pid")))
10
27.01.2020, 20:22

Usandops:

$ ps -o group,supgrp $$
GROUP    SUPGRP
muru     adm,cdrom,sudo,dip,www-data,plugdev,lpadmin,mlocate,sambashare,lxd,libvirtd,docker,muru

De man ps, las columnas de salida utilizadas para-o:

   egid        EGID      effective group ID number of the process as a
                         decimal integer.  (alias gid).

   egroup      EGROUP    effective group ID of the process.  This will be
                         the textual group ID, if it can be obtained and
                         the field width permits, or a decimal
                         representation otherwise.  (alias group).

   gid         GID       see egid.  (alias egid).

   group       GROUP     see egroup.  (alias egroup).

   supgid      SUPGID    group ids of supplementary groups, if any.  See
                         getgroups(2).

   supgrp      SUPGRP    group names of supplementary groups, if any.  See
                         getgroups(2).
3
27.01.2020, 20:22

Теги

Похожие вопросы