Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!hp-pcd!hpfcso!stroyan From: stroyan@hpfcso.FC.HP.COM (Mike Stroyan) Newsgroups: comp.sys.hp Subject: Re: How can I know his current group ID? Message-ID: <7370380@hpfcso.FC.HP.COM> Date: 24 Apr 91 01:04:54 GMT References: Organization: Hewlett-Packard, Fort Collins, CO, USA Lines: 27 >So foo belongs to several groups(A,B,C). Before he does job X, he >does newgrp A and he works under group ID A. > >I want a command, say wgrp, which returns a current group ID of >a user. The result would be like this. The situation is not as simple as you think. The group id is a property of each process, rather than a property of each user. When a user executes "newgrp A", a new shell process is started with the requested group id. Rather than showing the group id of a user, the best a "wgrp" command could do would be to show the group id of one or more processes. There is no simple kernel call that determines the group id of another process. The two possible approaches that occur to me would be to use the ptrace call or to read /dev/kmem. A ptrace(PT_ATTACH,...) call can be done by a super-user process to other processes. Then a ptrace(PT_RUAREA,...) call can be made to read the USER area of the process. As I understand it, this is not actually practical because ptrace will not work on processes that are shared text and are running in multiple processes. The other approach would be to get the data by reading /dev/kmem and digging out the process data from the kernel image. I have no experience with this kind of program. It is a very system dependent exercise which probably shouldn't be attempted without kernel sources. Mike Stroyan, mike_stroyan@fc.hp.com