Run a process as a different user Thanks to the “Ruby Cookbook” for this one
4 5 6 7 8 9 10 11 12
# File 'lib/process.rb', line 4 def as_uid(uid=0) old_euid, old_uid = Process.euid, Process.uid Process.euid, Process.uid = uid, uid begin yield ensure Process.euid, Process.uid = old_euid, old_uid end end