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
Linux Command to Empty All Files of a Directory
How to Exclude a Folder When Performing File Operations I.E. Cp, Mv, Rm and Chown etc. in Linux
Understanding Bash Short-Circuiting
Can't Su to User Jenkins After Installing Jenkins
Shellscript to Monitor a Log File If Keyword Triggers Then Execute a Command
How to Check the Version of Openmp on Linux
Rename Files in Multiple Directories to the Name of the Directory
One Command to Create and Change Directory
Where Are the Stacks for the Other Threads Located in a Process Virtual Address Space
How to Listen for Mouse Events in Linux
How to Sleep in the Linux Kernel Space
How to Get Started Developing on *Nix
How to List (Ls) the 5 Last Modified Files in a Directory
Linux Cross-Compilation for Arm Architecture
Fuzzy File Search in Linux Console