How to get the parent PID only in Solaris?

Hi,

I am using this command fuser_result=`fuser -f /web/$1/admin-*/logs/access` to get the parent pid of the process.

However, The output differs and at times it shows two pids instead of one thus failing the logic of my script. See output below:

bash-3.2$ fuser -f /web/prod/admin-server/logs/access
/web/prod/admin-server/logs/access:    17011o
bash-3.2$ fuser -f /web/prod/admin-server/logs/access
/web/prod/webserver7/admin-server/logs/access:    22852o   17011o
bash-3.2$ fuser -f /web/prod/admin-server/logs/access
/web/prod/admin-server/logs/access:    17011o

What would be the best way to get only the parent PID of a iPlanet webserver instance ?

In this case 17011 is the parent PID. Will the parent PID always show as the last entry of the output ? If not, then I am clueless. If yes, then I can use awk and get the last column of the output which happens to be 17011.

bash-3.2$ uname -a
SunOS mymac 5.10 Generic_150400-61 sun4v sparc sun4v

At times when your fuser command returns more than one PID, what are the processes with those PIDs? And what are the children of those PIDs doing?

From what you have said so far, it seems as though there might be two (or more) processes running on your system at some points in time that are accessing that file. You have not suggested any way to determine which parent you want when multiple parents meet your search criteria.

1 Like

We are running the iPlanet server process in "Multi-Process Mode" where the server spawns new processes depending upon the situation.

I would never know which is the parent process and that was the purpose of this thread ... to determine the parent process of iPlanet.

You can understand and read more about why and how multiple processes are spawned by the iPlanet server by clicking here.

I made some experiments, and indeed Solaris has always put the oldest process last.
Implementation proposal:

lastarg(){
  [ $# -gt 0 ] && (set -f; eval echo "\${$#}")
}
fuser_result=`fuser -f /web/"$1"/admin-*/logs/access 2>/dev/null`
fuser_result=`lastarg $fuser_result`