本文介绍了我的C / C ++应用程序如何确定root用户执行命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写需要root用户权限执行应用程序。如果由非root用户执行,它将退出并用PERROR消息,如终止:

I am writing an application that requires root user privileges to execute. If executed by a non root user, it exits and terminates with a perror message such as:

    pthread_getschedparam: Operation not permitted

我想使应用更加人性化。由于其早期初始化的一部分,我想它来检查,​​如果是由root或不执行它。如果不是根用户,它会present表明它只能由root运行,然后终止的消息。

I would like to make the application more user friendly. As part of its early initialization I would like it to check if it is being executed by root or not. And if not root, it would present a message indicating that it can only be run by root, and then terminate.

在此先感谢您的帮助。

推荐答案

的getuid geteuid 是显而易见的选择。

getuid or geteuid would be the obvious choices.

这篇关于我的C / C ++应用程序如何确定root用户执行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 03:43