Dead end in process, Unix team?

I was trying to figure out how to find out if process threads were blocked on a Unix / Linux computer? Also, is there a command to determine what stage (or condition) the process is in? If you know any tools, please suggest. Thank.

+3
source share
3 answers

Try a tool that tracks system calls, such straceas on Linux or tuscon HP-UX. When a deadlock occurs, you should see that the process hangs in a blocking call. This is not positive evidence. It can be a regular block. Then you need to determine if the block can be allowed for a while or not. This requires knowledge of the resource that the process expects.

Example

There is ... a feature in RHEL4 ... that can lead to a dead end ctime. Find an example program that demonstrates this behavior below:

#include <sys/time.h>
#include <time.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

volatile char *r;

void handler(int sig)
{
    time_t t;

    time(&t);
    r = ctime(&t);
}

int main()
{
    struct itimerval it;
    struct sigaction sa;
    time_t t;
    int counter = 0;

    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = handler;
    sigaction(SIGALRM, &sa, NULL);

    it.it_value.tv_sec = 0;
    it.it_value.tv_usec = 1000;
    it.it_interval.tv_sec = 0;
    it.it_interval.tv_usec = 1000;
    setitimer(ITIMER_REAL, &it, NULL);

    while(1) {
        counter++;
        time(&t);
        r = ctime(&t);
        printf("Loop %d\n",counter);
    }

    return 0;
}

This usually comes to a standstill after a couple of thousand iterations. Now attach straceso

strace -s4096 -p<PID>

PID - . , FUTEX_WAIT . ( , RHEL4, , ).

+1

/proc/<pid>/syscall, futex (op = FUTEX_WAIT) .

#!/bin/bash
#
# Find all processes that are executing a futex(2) call with op=FUTEX_WAIT
# In some cases this can be helpful in finding deadlock-ed processes.
#

test ! $UID -eq 0 && echo -e "WARNING: Not running as root, only processes for this user are being scanned\n" >&2;
pids=$(ps -u $UID -opid --no-headers)

for pid in $pids; do
        cat /proc/$pid/syscall |

        awk "{if (\$1 == 202 && \$3 == \"0x0\") {
                print $pid
        }}";

        # $1 is the syscall, we compare to 202 which is the futex call
        # See: /usr/include/asm/unistd.h

        # $2 is the 1st param, $3 is the 2nd param, etc
        # We compare the second param to 0x0 which is FUTEX_WAIT
        # See: /usr/include/linux/futex.h
done
+2

UNIX , . , , , . , , .

, ps -o pid,uname,command,state,stime,time. man ps .

-1

Source: https://habr.com/ru/post/1777319/


All Articles