Unix Proc Directory

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.

+5
source share
7 answers

Do you really want /proc/self/statusone that will provide you with information on the process currently ongoing.

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.

getuid() , , /proc/, .

+8

"id -u"?

+6

, /proc. getuid() $USER.

+3

, /proc Linux, UNIX . UID, getuid() geteuid().

, Linux, /proc/self/*, . , /proc "", , , , . , .

, : cat /proc/self/status

+3

, $USER. getuid id -u, /proc, , .

+2

/proc/process_id/status ( , Linux) ​​:

Uid:      1000    1000    1000    1000

uid , .

, , , getuid, uid .

: ah, /proc/self/status... - !

+1

, , . , . bash "UID", tcsh "uid" *nix. , tcsh "gid", bash.

0

All Articles