Shell script or shell command to locate specific process status?

Hello once again

How can i write a shell script or shell prompt command to locate a specific process as well as its status whether it is running or has been stooped, sleeping or in zombie state. For example, find out if mysqld process is running or not on my LInux system.

Thanks…

You can use a command like this:
ps cax | grep mysqld
then you can use case & switch to assign conditions depending on the result.

for example if we executed the command above, the output will be:
17525 ? Sl 2413:52 mysqld

You can get the 3rd column (Sl) using awk like this awk {' print $3 '}

Sl here means that the process waiting for an event to complete and is multi-threaded, here are all the states:

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.

Additional characters:

< 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

If you need any more assistant, please let me know :smile:

2 Likes

@modserv thnaks so much…

1 Like

You are most welcome :smile: