Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!umd5!uvaarpa!virginia!scl From: scl@virginia.acc.virginia.edu (Steve Losen) Newsgroups: comp.unix.questions Subject: Re: System V newgrp Message-ID: <535@virginia.acc.virginia.edu> Date: 29 Dec 87 21:26:20 GMT References: <4718@well.UUCP> <6866@ncoast.UUCP> <1014@bakerst.UUCP> <722@dolqci.UUCP> <3301@umn-cs.cs.umn.edu> Reply-To: scl@virginia.EDU Distribution: na Organization: University of Va., Charlottesville, VA Lines: 20 Keywords: group newgrp is really a shell builtin command that does this: exec /bin/newgrp group hence the newgrp process replaces the current shell process. Newgrp is a setuid to root program that simply does this: 1) setgid(2) to the desired group (after checking the /etc/group file of course), 2) setuid(2) back to the real user, (we can't let you be superuser, can we?) 3) execs another shell for you. Thus you are left with the same process but it has exec'ed two executables while you were wondering, "Why the hell is newgrp so slow??" Your shell now has a new group id, but you lost your environment in the process. By the way, you can never use newgrp in a shell script because of the exec. The script will never get to the command after the newgrp. -- Steve Losen University of Virginia Academic Computing Center