Sen alan bakabilirsiniz 5th çıkışında /proc/[pid]/stat.
$ ps -ejH | grep firefox
3043 2683 2683 ? 00:00:21 firefox
$ < /proc/3043/stat sed -n '$s/.*) [^ ]* [^ ]* \([^ ]*\).*/\1/p'
2683
Gönderen man proc:
/proc/[pid]/stat
Status information about the process. This is used by ps(1). It is defined in /usr/src/linux/fs/proc/array.c.
The fields, in order, with their proper scanf(3) format specifiers, are:
pid %d The process ID.
comm %s The filename of the executable, in parentheses. This is visible whether or not the executable is swapped out.
state %c One character from the string "RSDZTW" where R is running, S is sleeping in an interruptible wait, D is waiting in
uninterruptible disk sleep, Z is zombie, T is traced or stopped (on a signal), and W is paging.
ppid %d The PID of the parent.
pgrp %d The process group ID of the process.
session %d The session ID of the process.
Kullanamayacağınızı unutmayın:
awk '{print $5}'
Çünkü bu dosya boş bir ayrılmış liste değil. İkinci alan (işlem adı boşluklar veya hatta yeni satır karakterleri içerebilir). Örneğin, iş parçacıklarının çoğunda firefoxadlarında boşluk karakterleri bulunur.
Bu nedenle ), orada bir karakterin son oluşmasından sonra 3. alanı yazdırmanız gerekir .
awk '{print $5}'İşlem adı (ikinci alan) boşluk veya satırsonu karakterleri içerebileceğinden, size doğru yanıtı vereceğinizin garanti edilmediğini unutmayın .