It's pretty obvious how to get real user ID (Process.uid
) and effective user ID (Process.euid
) of the current running process in Ruby with stdlib help. But I wonder where is a sibling method for the saved set-user-ID, something like Process.suid
? There is only Process::UID.sid_available?
method, which allows to determine, does the running platform supports described feature.
Well, you are not going to like this, but AFAICT, this is the only way to get suid
for the process.
suid = `ps -o pid,suid`[/(?<=^#{Process.pid}\s)\s*\d+/].strip
#⇒ "1000"
Probably one should check if suid
is available upfront. Basically, this regexp searches for the line starting with the current process’ pid
.