F
F
freshcot2017-01-11 17:17:02
linux
freshcot, 2017-01-11 17:17:02

How to list processes without using ps command?

At the interview, I came across the following question: Display a list of processes without using ps, pgrep, pstree, top
How can this be done?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
shuraosipov, 2017-01-11
@shuraosipov

find /proc -maxdepth 1 -regex ".*[0-9]"
Return pid of all processes:

/proc/1
/proc/2
/proc/39
/proc/40
/proc/41
/proc/211

Excerpt from man 5 proc
/proc/[pid]
There is a numerical subdirectory for each running process; the subdirectory is named by the process ID. Each such subdirectory contains the following pseudo-files and directories.

D
Dmitry, 2017-01-11
@dmtrrr

/proc

P
planc, 2017-01-11
@planc

# pgrep ranger
5836
# head -2 /proc/5836/status
Name: ranger
State: S (sleeping)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question