69

The headline basically says it all. I have a program where I am only given the PID, nothing more really, and I would like to know how I get more information about the given process.

1
  • If you are working in python you probably want to use the psutil library. Do: psutil.Process(pid) to obtain the process object and then use its interface to retrieve information about memory/cpu etc. etc.
    – Bakuriu
    Sep 30, 2016 at 18:19

4 Answers 4

95
ps -Flww -p THE_PID

will show you some information. See the ps manpage for more information about the ps command. The "STANDARD FORMAT SPECIFIERS" section explains what the different columns mean.

3
  • 3
    Thanks. Why did you write ww instead of just one w? unix.stackexchange.com/questions/446099/…
    – Tim
    May 26, 2018 at 3:47
  • How do I get it to print the full non-truncated username?
    – matteo
    Dec 21, 2019 at 15:06
  • 6
    @Tim, from the manpage -w Wide output. Use this option twice for unlimited width. May 19, 2020 at 23:38
24

I don't know what is your exact requirement. but this may help you.

There is separate directory for every process with name as pid number in /proc .

ps -ef | grep docker 
root      1700     1  0 Sep20 ?        00:03:04 /usr/bin/docker daemon --raw-logs

In above output PID is 1700 .

goto /proc/1700

cd /proc/1700

and do ls there

ls
attr       clear_refs       cpuset   fd       limits     mem         net        oom_score      projid_map  sessionid  stat     task
autogroup  cmdline          cwd      fdinfo   loginuid   mountinfo   ns         oom_score_adj  root        setgroups  statm    timers
auxv       comm             environ  gid_map  map_files  mounts      numa_maps  pagemap        sched       smaps      status   uid_map
cgroup     coredump_filter  exe      io       maps       mountstats  oom_adj    personality    schedstat   stack      syscall  wchan

there is many file that have all information about process.

Like:

cat /proc/1700/status

Name:   docker
State:  S (sleeping)
Tgid:   1700
Ngid:   0
Pid:    1700
PPid:   1
TracerPid:  0
Uid:    0   0   0   0
Gid:    0   0   0   0
FDSize: 64
Groups: 0 999 
VmPeak:   527576 kB
VmSize:   527512 kB
VmLck:         0 kB
VmPin:         0 kB
VmHWM:     46032 kB
VmRSS:     34180 kB
VmData:   449308 kB
VmStk:       136 kB
VmExe:     28324 kB
VmLib:      4236 kB
VmPTE:       296 kB
VmSwap:     5324 kB
Threads:    12
SigQ:   0/63662
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000000000
SigCgt: ffffffffffc1feff
CapInh: 0000000000000000
CapPrm: 0000003fffffffff
CapEff: 0000003fffffffff
CapBnd: 0000003fffffffff
Seccomp:    0
Cpus_allowed:   f
Cpus_allowed_list:  0-3
Mems_allowed:   00000000,00000001
Mems_allowed_list:  0
voluntary_ctxt_switches:    437726
nonvoluntary_ctxt_switches: 27579

If you need basic command to get process information then you can easily get using command:

man ps
6

To add to the ps answer there is also the pidstat command which will show additional stats like the time spent in user mode or the occupation of the cpu. You can use it with:

# pidstat -p 51648

You can also add the -d flag to add details about I/O:

# pidstat -p 51648 -d

And you can also an integer as a second parameter to make the command refresh each X seconds:

# pidstat -p 51648 3
1
  • Debian/Ubuntu provide pidstat with the sysstat package.
    – Abdull
    Dec 22, 2023 at 9:59
0

px, available via the px package, is a great tool for giving detailed information about a running process.

px $SOME_PID

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .