How to Tell What a Linux Process Is Waiting For

How do I tell what a Linux process is waiting for?

Whatever process it is, you use top to check the state. Then you could run it through truss or strace. That should detail what is going on. If that is not possible, hook it up to gdb. Tools like iostat might show you in general what is going on (e.g. if disk is bottleneck).

How to find out which process is consuming wait CPU (i.e. I/O blocked)

iotop and latencytop may be helpful. Neither gives exactly "CPU wait time caused by a process" -- I'm not sure it even makes sense, because the CPU can and does go off to service other processes while waiting for IO -- but these two tools give overviews of (respectively) system I/O traffic and scheduling delays.

How to check if a process is waiting due to call to wait() or waitpid()?

Yes, waitqueue current->wait_chldexit may contain either single element for current process or non elements at all.

No one wakes up given waitqueue, instead waiting is broken by a signal arised from the child thread.

By checking this waitqueue for some thread, you may detect whether that the thread is blocked in wait() or waitpid() call.

how to figure out if process is really running or waiting to run on Linux?

The struct task_struct contains a long to represent current state:

volatile long state;          /* -1 unrunnable, 0 runnable, >0 stopped */

This simply indicates if a process is 'runnable'.

To see the currently executing process you should look at the runqueue. Specifically a struct rq (as defined in kernel/sched/sched.h) contains:

struct task_struct *curr, *idle, *stop;

The pointer *curr is the currently running process on this runqueue (there exists a runqueue per CPU).

You should consult files under kernel/sched/ to see how the Kernel determines which processes should be scheduled according to the different scheduling algorithms if you are interested in exactly how it arrives at the running state.



Related Topics



Leave a reply



Submit