TL; DR
Dalam salah satu komentar Anda, Anda menyatakan:
Yah situasi tepatnya saya adalah: Saya memiliki path ke file. Terkunci jika firefox sedang berjalan. Saya ingin melihat apakah terkunci atau tidak memberi tahu apakah firefox sedang berjalan.
Pertanyaan awal Anda tentang file penguncian sepertinya jauh ketika ada cara yang lebih mudah untuk mengetahui apakah Firefox berjalan untuk pengguna tertentu, dan untuk memeriksa status prosesnya.
Memeriksa Status Proses
Cara yang lebih masuk akal untuk menemukan PID dari proses yang diberikan adalah dengan menggunakan pgrep dari paket procps . Sebagai contoh:
$ pgrep -u $LOGNAME firefox
5671
Anda kemudian dapat memeriksa status PID dengan ps :
$ ps 5671
PID TTY STAT TIME COMMAND
5671 ? Sl 105:47 /usr/lib/firefox/firefox
atau hanya mendapatkan bendera negara tanpa cacat lainnya:
$ ps -ho stat $(pgrep -u $LOGNAME firefox)
Sl
Satu sistem saya, one-liner di atas secara konsisten hanya membutuhkan 1,4 milidetik untuk menyelesaikannya. Jarak tempuh Anda mungkin beragam.
Kode Status Proses
Bagian PROSES STATE CODES dari ps (1) merinci apa arti berbagai bendera negara. Pada Ubuntu 14.04 halaman manual mengatakan:
PROCESS STATE CODES
Here are the different values that the s, stat and state output
specifiers (header "STAT" or "S") will display to describe the state of
a process:
D uninterruptible sleep (usually IO)
R running or runnable (on run queue)
S interruptible sleep (waiting for an event to complete)
T stopped, either by a job control signal or because it is
being traced
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z defunct ("zombie") process, terminated but not reaped by
its parent
For BSD formats and when the stat keyword is used, additional
characters may be displayed:
< high-priority (not nice to other users)
N low-priority (nice to other users)
L has pages locked into memory (for real-time and custom IO)
s is a session leader
l is multi-threaded (using CLONE_THREAD, like NPTL pthreads
do)
+ is in the foreground process group