check the process is active using ‘pstack’

Hello Readers,

Happy new years!!

I know it’s been long since last post but I like the way you follow my blog. Thanks a lot. You are the people who encourage me to write/help new comers/learners and spread the solutions of the some basic but important problems.

So, people today I am going to talk about pstack.

If you new to linux or operating system or new to the word of ‘pstack’, congratulations because you are going to earn more knowledge about it.

So at very high level, pstack is basically a command which we can use on linux machine to know whether the any process is hung or it’s working.

So, lets go in to deep.

The pstack command will print a hexadecimal dump of the process stack, thus providing important information about a suspect process on the affected system.

pstack attaches to the active process named by the pid on the command line, and prints out an execution stack trace. If ELF symbols exist in the binary (usually the case unless you have run strip(1)), then symbolic addresses are printed as well.

If the process is part of a thread group, then pstack will print out a stack trace for each of the threads in the group.

Lets talk about installation:

Its very easy.

Following is the command to execute.

yum install pstack -y or apt-get install pstack -y

Once it get installed you can check the installation by typing ‘pstack’ command.

You can check the sub commands using pstack –help.

The basic syntax is pstack [process id]

example – pstack 8798

It will print the stacktrace.

Like – #pstack 1094
1094:   /usr/lib/sendmail -bd -q15m
fefc6004 pollsys  (ffbfd080, 3, ffbfd128, 0)
fef66f20 pselect  (ffbfd080, feff2530, feff2530, 40, ffbfd128, 0) + 1c8
fef67298 select   (8, ffbfdb18, 0, 0, ffbfdb10, 109400) + a0
0002852c getrequests (121744, 7, 7, 11c388, 11c2f8, 3) + 690
00048a94 main     (0, 13f800, 64, 10f800, 121c00, e8c00) + 5b68
0001f6e0 _start   (0, 0, 0, 0, 0, 0) + 108

Seeing this output you can grab the necessary information from the output.

Now question is how to confirm the process is hung or its no longer active.

Answer is –

Just take pstack of process in file and take the same after some interval of time and compare the files. If there is difference in files then process is active.

example : pstack 8979 >  a.txt

after x minutes pstack 8979 > b.txt

To check is there any difference in two files , run a command ‘diff a.txt b.txt’

Thank you people, stay tuned for more important useful knowledge.