Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Running a daemon process as another user

by toadi (Chaplain)
on Oct 27, 2004 at 08:30 UTC ( #402930=note: print w/ replies, xml ) Need Help??


in reply to Re: Running a daemon process as another user
in thread Running a daemon process as another user

ok this is very strange:

use POSIX qw/setuid setsid/; BEGIN { setuid scalar getpwnam 'qf3' or die $!; # Fork. my $pidFile = '/some/path/pid'; my $pid = fork; if ($pid) # parent: save PID { open PIDFILE, ">$pidFile" or die "can't open $pidFile: $!\n"; print PIDFILE $pid; close PIDFILE; exit 0; } } print "USER: ". getpwuid($<) . "\n";

USER will be root, but when I do a ps -ef it does:

toadi 20510 1 14 04:56 pts/0 00:00:01 /usr/bin/perl /some/ +path/daemon


--
My opinions may have changed,
but not the fact that I am right


Comment on Re^2: Running a daemon process as another user
Select or Download Code
Re^3: Running a daemon process as another user
by Happy-the-monk (Monsignor) on Oct 27, 2004 at 09:06 UTC

    print "USER: ". getpwuid($<) . "\n";

    USER will be root, but when I do a ps -ef it does:

    Sure it is, because   $<   is the real uid (you used to be root).

    Use the effective uid   $>   to display the new identity. See  perlvar.

    Cheers, Sören

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://402930]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2014-10-02 03:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (45 votes), past polls