Search code examples
linuxsudo

Fork with user privileges/rights


Is it possible to fork a process and to run a program as normal user, e.g. with sudo rights? Or, if with sudo, with normal rights?


Solution

  • If your process runs as root, after a fork() you can execute setgid() and setuid(), and run as a normal user in the child process, without affecting the parent process, that continues to run as root.