If you suspect a deadlock, do a ps aux | grep <exe name>
, if in output, the PROCESS STATE CODE
is D
(Uninterruptible sleep) means it is a deadlock.
Because as @daijo explained, say you have two threads T1
& T2
and two critical sections each protected by semaphores S1 & S2
then if T1
acquires S1
and T2
acquires S2
and after that they try to acquire the other lock before relinquishing the one already held by them, this will lead to a deadlock and on doing a ps aux | grep <exe name>
, the process state code
will be D
(ie Uninterruptible sleep).
Tools:
Valgrind, Lockdep (linux kernel utility)
Check this link on types of deadlocks and how to avoid them :
http://cmdlinelinux.blogspot.com/2014/01/linux-kernel-deadlocks-and-how-to-avoid.html
Edit: ps aux
output D
"could" mean process is in deadlock, from this redhat doc:
Uninterruptible Sleep State
An Uninterruptible sleep state is one
that won't handle a signal right away. It will wake only as a result
of a waited-upon resource becoming available or after a time-out
occurs during that wait (if the time-out is specified when the process
is put to sleep).