Determine which group(s) a running process is in?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I try to determine which group(s) a running child process has inherited. I want to find all groups the process is in for his uid. Is there a way to determine this via /proc filesystem?







share|improve this question





















  • Are you looking for the groups associated to the process's UID (which one?), or for the groups that the process is in? The two are usually the same, but they might not be (e.g. if the process was run with sudo -g, or if the group database changed since the user logged in).
    – Gilles
    May 17 at 15:58














up vote
3
down vote

favorite












I try to determine which group(s) a running child process has inherited. I want to find all groups the process is in for his uid. Is there a way to determine this via /proc filesystem?







share|improve this question





















  • Are you looking for the groups associated to the process's UID (which one?), or for the groups that the process is in? The two are usually the same, but they might not be (e.g. if the process was run with sudo -g, or if the group database changed since the user logged in).
    – Gilles
    May 17 at 15:58












up vote
3
down vote

favorite









up vote
3
down vote

favorite











I try to determine which group(s) a running child process has inherited. I want to find all groups the process is in for his uid. Is there a way to determine this via /proc filesystem?







share|improve this question













I try to determine which group(s) a running child process has inherited. I want to find all groups the process is in for his uid. Is there a way to determine this via /proc filesystem?









share|improve this question












share|improve this question




share|improve this question








edited May 17 at 20:42









Roger Lipscombe

714620




714620









asked May 17 at 12:07









Mandragor

395210




395210











  • Are you looking for the groups associated to the process's UID (which one?), or for the groups that the process is in? The two are usually the same, but they might not be (e.g. if the process was run with sudo -g, or if the group database changed since the user logged in).
    – Gilles
    May 17 at 15:58
















  • Are you looking for the groups associated to the process's UID (which one?), or for the groups that the process is in? The two are usually the same, but they might not be (e.g. if the process was run with sudo -g, or if the group database changed since the user logged in).
    – Gilles
    May 17 at 15:58















Are you looking for the groups associated to the process's UID (which one?), or for the groups that the process is in? The two are usually the same, but they might not be (e.g. if the process was run with sudo -g, or if the group database changed since the user logged in).
– Gilles
May 17 at 15:58




Are you looking for the groups associated to the process's UID (which one?), or for the groups that the process is in? The two are usually the same, but they might not be (e.g. if the process was run with sudo -g, or if the group database changed since the user logged in).
– Gilles
May 17 at 15:58










4 Answers
4






active

oldest

votes

















up vote
4
down vote













The list of groups is given under Groups in /proc/<pid>/status; for example,



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


The primary group is given under Gid:



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


ps is also capable of showing the groups of a process, as the other answers indicate.






share|improve this answer






























    up vote
    3
    down vote













    Using ps:



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


    From man ps, the output columns used for -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).





    share|improve this answer




























      up vote
      3
      down vote













      For the effective group id, real group id and supplementary group ids (as used for access control):



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


      gid and rgid are fairly portable, supgid less so (all 3 would be available with the ps from procps as typically found on Linux-based systems).



      group, rgroup and supgrp can be used to translate group ids to group names, but note that for group ids that have several corresponding group names, only one of them will be shown (same as for ls -l vs ls -n or anything that deals with user or group names based on ids).



      For the process group id (as used for terminal job control):



      ps -o pgid -p "$pid"





      share|improve this answer






























        up vote
        -2
        down vote













        On a UNIX system derived from SVr4, you may call:



        pcred <prcess-id>


        Note that the official procfs is not ASCII but binary.






        share|improve this answer





















        • The question is about Linux, which is not (much) derived from SVr4, so this doesn't answer the question. Also there is no such thing as “the official procfs”: each Unix variant has its own implementation of it, or doesn't have one.
          – Gilles
          May 17 at 16:00










        • You seem to miss that there was a paper on procfs and another one on procfs-2. Linux has not much more in common with that paper than the name procfs. Since this portal is about UNIX, it is obvious that there are people who like to know how things work on UNIX even thought the question might have been Linux specific.
          – schily
          May 17 at 20:09











        Your Answer







        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "106"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        convertImagesToLinks: false,
        noModals: false,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );








         

        draft saved


        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f444351%2fdetermine-which-groups-a-running-process-is-in%23new-answer', 'question_page');

        );

        Post as a guest






























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        4
        down vote













        The list of groups is given under Groups in /proc/<pid>/status; for example,



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


        The primary group is given under Gid:



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


        ps is also capable of showing the groups of a process, as the other answers indicate.






        share|improve this answer



























          up vote
          4
          down vote













          The list of groups is given under Groups in /proc/<pid>/status; for example,



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


          The primary group is given under Gid:



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


          ps is also capable of showing the groups of a process, as the other answers indicate.






          share|improve this answer

























            up vote
            4
            down vote










            up vote
            4
            down vote









            The list of groups is given under Groups in /proc/<pid>/status; for example,



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


            The primary group is given under Gid:



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


            ps is also capable of showing the groups of a process, as the other answers indicate.






            share|improve this answer















            The list of groups is given under Groups in /proc/<pid>/status; for example,



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


            The primary group is given under Gid:



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


            ps is also capable of showing the groups of a process, as the other answers indicate.







            share|improve this answer















            share|improve this answer



            share|improve this answer








            edited May 17 at 13:07


























            answered May 17 at 12:13









            AlexP

            6,616823




            6,616823






















                up vote
                3
                down vote













                Using ps:



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


                From man ps, the output columns used for -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).





                share|improve this answer

























                  up vote
                  3
                  down vote













                  Using ps:



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


                  From man ps, the output columns used for -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).





                  share|improve this answer























                    up vote
                    3
                    down vote










                    up vote
                    3
                    down vote









                    Using ps:



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


                    From man ps, the output columns used for -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).





                    share|improve this answer













                    Using ps:



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


                    From man ps, the output columns used for -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).






                    share|improve this answer













                    share|improve this answer



                    share|improve this answer











                    answered May 17 at 12:52









                    muru

                    33.2k576140




                    33.2k576140




















                        up vote
                        3
                        down vote













                        For the effective group id, real group id and supplementary group ids (as used for access control):



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


                        gid and rgid are fairly portable, supgid less so (all 3 would be available with the ps from procps as typically found on Linux-based systems).



                        group, rgroup and supgrp can be used to translate group ids to group names, but note that for group ids that have several corresponding group names, only one of them will be shown (same as for ls -l vs ls -n or anything that deals with user or group names based on ids).



                        For the process group id (as used for terminal job control):



                        ps -o pgid -p "$pid"





                        share|improve this answer



























                          up vote
                          3
                          down vote













                          For the effective group id, real group id and supplementary group ids (as used for access control):



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


                          gid and rgid are fairly portable, supgid less so (all 3 would be available with the ps from procps as typically found on Linux-based systems).



                          group, rgroup and supgrp can be used to translate group ids to group names, but note that for group ids that have several corresponding group names, only one of them will be shown (same as for ls -l vs ls -n or anything that deals with user or group names based on ids).



                          For the process group id (as used for terminal job control):



                          ps -o pgid -p "$pid"





                          share|improve this answer

























                            up vote
                            3
                            down vote










                            up vote
                            3
                            down vote









                            For the effective group id, real group id and supplementary group ids (as used for access control):



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


                            gid and rgid are fairly portable, supgid less so (all 3 would be available with the ps from procps as typically found on Linux-based systems).



                            group, rgroup and supgrp can be used to translate group ids to group names, but note that for group ids that have several corresponding group names, only one of them will be shown (same as for ls -l vs ls -n or anything that deals with user or group names based on ids).



                            For the process group id (as used for terminal job control):



                            ps -o pgid -p "$pid"





                            share|improve this answer















                            For the effective group id, real group id and supplementary group ids (as used for access control):



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


                            gid and rgid are fairly portable, supgid less so (all 3 would be available with the ps from procps as typically found on Linux-based systems).



                            group, rgroup and supgrp can be used to translate group ids to group names, but note that for group ids that have several corresponding group names, only one of them will be shown (same as for ls -l vs ls -n or anything that deals with user or group names based on ids).



                            For the process group id (as used for terminal job control):



                            ps -o pgid -p "$pid"






                            share|improve this answer















                            share|improve this answer



                            share|improve this answer








                            edited May 17 at 12:58


























                            answered May 17 at 12:52









                            Stéphane Chazelas

                            279k53513845




                            279k53513845




















                                up vote
                                -2
                                down vote













                                On a UNIX system derived from SVr4, you may call:



                                pcred <prcess-id>


                                Note that the official procfs is not ASCII but binary.






                                share|improve this answer





















                                • The question is about Linux, which is not (much) derived from SVr4, so this doesn't answer the question. Also there is no such thing as “the official procfs”: each Unix variant has its own implementation of it, or doesn't have one.
                                  – Gilles
                                  May 17 at 16:00










                                • You seem to miss that there was a paper on procfs and another one on procfs-2. Linux has not much more in common with that paper than the name procfs. Since this portal is about UNIX, it is obvious that there are people who like to know how things work on UNIX even thought the question might have been Linux specific.
                                  – schily
                                  May 17 at 20:09















                                up vote
                                -2
                                down vote













                                On a UNIX system derived from SVr4, you may call:



                                pcred <prcess-id>


                                Note that the official procfs is not ASCII but binary.






                                share|improve this answer





















                                • The question is about Linux, which is not (much) derived from SVr4, so this doesn't answer the question. Also there is no such thing as “the official procfs”: each Unix variant has its own implementation of it, or doesn't have one.
                                  – Gilles
                                  May 17 at 16:00










                                • You seem to miss that there was a paper on procfs and another one on procfs-2. Linux has not much more in common with that paper than the name procfs. Since this portal is about UNIX, it is obvious that there are people who like to know how things work on UNIX even thought the question might have been Linux specific.
                                  – schily
                                  May 17 at 20:09













                                up vote
                                -2
                                down vote










                                up vote
                                -2
                                down vote









                                On a UNIX system derived from SVr4, you may call:



                                pcred <prcess-id>


                                Note that the official procfs is not ASCII but binary.






                                share|improve this answer













                                On a UNIX system derived from SVr4, you may call:



                                pcred <prcess-id>


                                Note that the official procfs is not ASCII but binary.







                                share|improve this answer













                                share|improve this answer



                                share|improve this answer











                                answered May 17 at 12:38









                                schily

                                8,65421435




                                8,65421435











                                • The question is about Linux, which is not (much) derived from SVr4, so this doesn't answer the question. Also there is no such thing as “the official procfs”: each Unix variant has its own implementation of it, or doesn't have one.
                                  – Gilles
                                  May 17 at 16:00










                                • You seem to miss that there was a paper on procfs and another one on procfs-2. Linux has not much more in common with that paper than the name procfs. Since this portal is about UNIX, it is obvious that there are people who like to know how things work on UNIX even thought the question might have been Linux specific.
                                  – schily
                                  May 17 at 20:09

















                                • The question is about Linux, which is not (much) derived from SVr4, so this doesn't answer the question. Also there is no such thing as “the official procfs”: each Unix variant has its own implementation of it, or doesn't have one.
                                  – Gilles
                                  May 17 at 16:00










                                • You seem to miss that there was a paper on procfs and another one on procfs-2. Linux has not much more in common with that paper than the name procfs. Since this portal is about UNIX, it is obvious that there are people who like to know how things work on UNIX even thought the question might have been Linux specific.
                                  – schily
                                  May 17 at 20:09
















                                The question is about Linux, which is not (much) derived from SVr4, so this doesn't answer the question. Also there is no such thing as “the official procfs”: each Unix variant has its own implementation of it, or doesn't have one.
                                – Gilles
                                May 17 at 16:00




                                The question is about Linux, which is not (much) derived from SVr4, so this doesn't answer the question. Also there is no such thing as “the official procfs”: each Unix variant has its own implementation of it, or doesn't have one.
                                – Gilles
                                May 17 at 16:00












                                You seem to miss that there was a paper on procfs and another one on procfs-2. Linux has not much more in common with that paper than the name procfs. Since this portal is about UNIX, it is obvious that there are people who like to know how things work on UNIX even thought the question might have been Linux specific.
                                – schily
                                May 17 at 20:09





                                You seem to miss that there was a paper on procfs and another one on procfs-2. Linux has not much more in common with that paper than the name procfs. Since this portal is about UNIX, it is obvious that there are people who like to know how things work on UNIX even thought the question might have been Linux specific.
                                – schily
                                May 17 at 20:09













                                 

                                draft saved


                                draft discarded


























                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f444351%2fdetermine-which-groups-a-running-process-is-in%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Popular posts from this blog

                                How to check contact read email or not when send email to Individual?

                                Displaying single band from multi-band raster using QGIS

                                How many registers does an x86_64 CPU actually have?