Finding out User Id given Process id

Finding out User Id given Process id

Post by Roy Harringt » Wed, 25 Sep 1996 04:00:00



Hopefully someone out there can help me. I need to find out the User Id of
a process, given it's pid. I need some generic system call, which will work
across a range of UNIX systems. I know I could use ps and grep the results,
but I want to do this from C without using ps.

Any help appreciated (even if telling me it's not possible)

Roy Harrington

 
 
 

Finding out User Id given Process id

Post by Urs Thuerma » Thu, 26 Sep 1996 04:00:00



> Hopefully someone out there can help me. I need to find out the User Id of
> a process, given it's pid. I need some generic system call, which will work
> across a range of UNIX systems. I know I could use ps and grep the results,
> but I want to do this from C without using ps.

> Any help appreciated (even if telling me it's not possible)

Unfortunately, "not possible" is AFAIK the answer to your question.
The system call interface lets you only ask for your own uid, and
there is nothing a lib or an own routine can do about it.

You can only do like ps, and read /dev/kmem or the entries in /proc,
ifyour system has it.  That, however, is not portable but very system
dependent.

urs

 
 
 

Finding out User Id given Process id

Post by Yiorgos Adamopoul » Thu, 26 Sep 1996 04:00:00



: > Hopefully someone out there can help me. I need to find out the User Id of
: > a process, given it's pid. I need some generic system call, which will work
: > across a range of UNIX systems. I know I could use ps and grep the results,
: > but I want to do this from C without using ps.

If you work on Solaris2.x you may experiment with the code of showid, but
in anycase the info you want requires group privileges or root (depending
your configuration).

-Yiorgos.

 
 
 

Finding out User Id given Process id

Post by Christopher E Kingsbu » Sat, 28 Sep 1996 04:00:00


: Hopefully someone out there can help me. I need to find out the User Id of
: a process, given it's pid. I need some generic system call, which will work
: across a range of UNIX systems. I know I could use ps and grep the results,
: but I want to do this from C without using ps.

Just check the owner of the corresponding process file in /proc.  This won't
work across all platforms, but its a start.

Chris Kingsbury

 
 
 

Finding out User Id given Process id

Post by David 'Mort' Mortm » Tue, 01 Oct 1996 04:00:00



>Hopefully someone out there can help me. I need to find out the User Id of
>a process, given it's pid. I need some generic system call, which will work
>across a range of UNIX systems. I know I could use ps and grep the results,
>but I want to do this from C without using ps.

it seems that cuserid() would work, or if your on non SYSV machine
you could do something like a getlogin() along with a getpwuid() or
some such thing.

note that cuserid() relies on /var/adm/utmp so itsn't the most secure
way of doing things.

-Mort

 
 
 

Finding out User Id given Process id

Post by Eric Fisch » Tue, 01 Oct 1996 04:00:00


[Roy Harrington wants to find out the user id of a process, given its
 process ID, without using ps]


Quote:> it seems that cuserid() would work, or if your on non SYSV machine
> you could do something like a getlogin() along with a getpwuid() or
> some such thing.

No, that'll give you *your* process's login name, not the user
ID of an arbitary process.

Not that I know a good way to do this...  The only portable thing that
comes to mind, short of resorting to the "ps" command or, if you have
one, a /proc file system, is to have a setuid root process that cycles
through the entire possible uid_t range and, as each of these users,
does a kill(pid, 0) on the process you're interested in.  Signal 0 is
non-destructive, but if the call succeeds you know you've found the
right user, and if it fails you go on checking.  Ick!

Eric   [Hi, Mort]

 
 
 

1. Finding out User Id given Process id

If your system supports the pstat set of calls, you can try using pstat.
At least on HP-UX, there are wrapper routines for this such as
pstat_getproc, which returns process specific info, taking the pid as
one of the args. Even otherwise, I guess there must be some call which
can return process specific info. This will definitely contain UID as
one of the fields ( and a lot more other info if you wish ).
Srinivasan.

2. opti /dev/dsp problem

3. Process id to user id

4. Sense Key Media Errors with Solaris 2.4 and 4mm DAT autoloader

5. user id vs effective user id

6. Oops! I goofed (vtprint 1.22)!

7. How to make wine access ports directly.?

8. (Review ID: 159248) Starting Tomcat servlet engine gives HotSpot Virtual Machine Error: 11, error ID

9. Get process ids of all processes associated with a given ip-address

10. Matching thread ids to process ids

11. Find widget id without having parent id????