If you are a user of your system that has sudo privileges to run commands as root , just sudo to the command.
system("sudo yum install some-package");
If you want someone to be able to do this, then you must be the administrator of your system, change the owner of the file as root and change the permissions of your executable file to run as root . By doing so, you do not need to change your system() command line using sudo .
chmod +s my_program chown root my_program
Understand that this can open you security problems if you have not proven that your program has no security problems.
The file system may be such as to prevent you from setting the setuid bit in your program. If you need more information on these lines, you should contact SuperUser .
source share