I am trying to find a virtual file containing the current user id. I was told that I can find it in the proc directory, but not quite sure which file.
Do you really want /proc/self/statusone that will provide you with information on the process currently ongoing.
/proc/self/status
Here is an example:
$ cat /proc/self/status Name: cat State: R (running) Tgid: 17618 Pid: 17618 PPid: 3083 TracerPid: 0 Uid: 500 500 500 500 Gid: 500 500 500 500 FDSize: 32 Groups: 10 488 500 VmPeak: 4792 kB VmSize: 4792 kB VmLck: 0 kB VmHWM: 432 kB VmRSS: 432 kB VmData: 156 kB VmStk: 84 kB VmExe: 32 kB VmLib: 1532 kB VmPTE: 24 kB Threads: 1 SigQ: 0/32268 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 0000000000000000 SigCgt: 0000000000000000 CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 Cpus_allowed: 00000003 Mems_allowed: 1 voluntary_ctxt_switches: 0 nonvoluntary_ctxt_switches: 3
You will probably want to see the first numbers on the Uid and Gid lines. You can see which uid numbers are mapped to which username by looking at /etc/passwdor calling the appropriate functions to match the uid with the username in any language that you use.
/etc/passwd
getuid() , , /proc/, .
getuid()
/proc/
"id -u"?
id -u
, /proc. getuid() $USER.
/proc
$USER
, /proc Linux, UNIX . UID, getuid() geteuid().
geteuid()
, Linux, /proc/self/*, . , /proc "", , , , . , .
/proc/self/*
, : cat /proc/self/status
cat /proc/self/status
, $USER. getuid id -u, /proc, , .
getuid
/proc/process_id/status ( , Linux) :
/proc/process_id/status
Uid: 1000 1000 1000 1000
uid , .
, , , getuid, uid .
: ah, /proc/self/status... - !
, , . , . bash "UID", tcsh "uid" *nix. , tcsh "gid", bash.
*nix