通过一个用户名找出组名,子程序如下:
复制代码 代码如下:
sub getUserGroup{
my ($username) = @_;
my ($name, $passwd, $uid, $gid)=getpwnam($username);
my $group = getgrgid($gid);
return $group;
}
传入用户名:
复制代码 代码如下:
my $execUsername = getpwuid( $< );
my $group = &getUserGroup($execUsername);