How to determine what user and group a Python script is running as?

Posted by Chirael on Stack Overflow See other posts from Stack Overflow or by Chirael
Published on 2010-06-15T03:15:11Z Indexed on 2010/06/15 3:22 UTC
Read the original article Hit count: 231

Filed under:
|
|

I have a CGI script that is getting an "IOError: [Errno 13] Permission denied" error in the stack trace in the web server's error log.

As part of debugging this problem, I'd like to add a little bit of code to the script to print the user and (especially) group that the script is running as, into the error log (presumably STDERR).

I know I can just print the values to sys.stderr, but how do I figure out what user and group the script is running as?

(I'm particularly interested in the group, so the $USER environment variable won't help; the CGI script has the setgid bit set so it should be running as group "list" instead of the web server's "www-data" - but I need code to see if that's actually happening.)

© Stack Overflow or respective owner

Related posts about python

Related posts about unix