This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Start a process as another user

Tags: kdesu kdesu kdesu
(comma "," separated)
User avatar
JanGerrit
Moderator
Posts
647
Karma
3
OS

Start a process as another user

Fri Aug 14, 2009 2:52 pm
I want to start a process as another user from a C++ program (it should be detached). But I have only the UID (user identification number I think). How can I do this?
The shell command is:
kdesu -u ME -c a command with arguments
But there I must know the user name

Thanks in advance


Image
User avatar
anda_skoa
KDE Developer
Posts
783
Karma
4
OS

Re: Start a process as another user

Fri Aug 14, 2009 6:18 pm
You could try to map the user id to the user name, but maybe there is a better approach to the overall problem.

What's your use case?

Cheers,
_


anda_skoa, proud to be a member of KDE forums since 2008-Oct.
User avatar
JanGerrit
Moderator
Posts
647
Karma
3
OS

Re: Start a process as another user

Fri Aug 14, 2009 6:37 pm
There's an idea in Brainstorm to implement a runner to kill processes (brainstorm.php#idea62623). And the API ksysguardd uses returns the uid of the process owner (or I didn't see a method to return the user name) but KDE-su needs the user name. I could read the user names out of /etc/passwd but a easier way would be better.


Image
User avatar
JanGerrit
Moderator
Posts
647
Karma
3
OS
I mapped the user name by looking in /etc/passwd. But Pino Toscano (pino) corrected it by using KUser (which is quite easier) so this topic is solved:
Code: Select all
KUser user(uid);
    if (user.isValid()) {
        return user.loginName();
    }


Image


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]