How to get the parent PID only in Solaris?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get the parent PID only in Solaris?
# 1  
Old 07-30-2018
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:
Code:
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.
Code:
bash-3.2$ uname -a
SunOS mymac 5.10 Generic_150400-61 sun4v sparc sun4v


Last edited by rbatte1; 07-31-2018 at 05:43 AM..
# 2  
Old 07-30-2018
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.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 07-31-2018
Quote:
Originally Posted by Don Cragun
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.
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.
# 4  
Old 07-31-2018
I made some experiments, and indeed Solaris has always put the oldest process last.
Implementation proposal:
Code:
lastarg(){
  [ $# -gt 0 ] && (set -f; eval echo "\${$#}")
}
fuser_result=`fuser -f /web/"$1"/admin-*/logs/access 2>/dev/null`
fuser_result=`lastarg $fuser_result`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Trying to debug truss command of PID in Solaris 10.

I'm getting the following output from a truss operation of a PID from an application that will not start properly, something with the writing to an archive. Here is the output: open("arch/chkpt.arch", O_RDWR) Err#13 EACCES open("arch/chkpt.arch", O_RDWR|O_CREAT|O_TRUNC, 0666)... (6 Replies)
Discussion started by: chadpierce62
6 Replies

2. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

3. Shell Programming and Scripting

how to grep parent process PID in shell scripting

hi all, for an example: $ ps -ef | grep apache | awk '{ print $2, $3 }' 24073 11784 28021 1 28022 1 28038 1 28041 28040 28045 28041 28047 28041 28040 1 28049 28041 28051 28041 28053 28041 28030 1 28054 28041 28055 28041 28056 28041 28057 28041 (5 Replies)
Discussion started by: raghur77
5 Replies

4. UNIX for Dummies Questions & Answers

Need to get pid of a process and have to store the pid in a variable

Hi, I need to get the pid of a process and have to store the pid in a variable and i want to use this value(pid) of the variable for some process. Please can anyone tell me how to get the pid of a process and store it in a variable. please help me on this. Thanks in advance, Amudha (7 Replies)
Discussion started by: samudha
7 Replies

5. Shell Programming and Scripting

full path of a file situated either in parent's dir. or parent's parent dir. so on...

hi experts(novice people can stay away as it is no child's game), i am developing a script which works like recycle bin of windows. the problem i am facing is that when ever i am trying to delete a file which is situated in parent directory or parent's parent directory i am unable to... (1 Reply)
Discussion started by: yahoo!
1 Replies

6. Shell Programming and Scripting

Environment Variable Parent PID

I have always used the "$$" environment variable to find the current process number. Is there any similar way or perhaps something else to easily find the parent process number? I realize I could do something like ps and grep for the process and cut or awk out the parent process but I wanted to... (1 Reply)
Discussion started by: scotbuff
1 Replies

7. Shell Programming and Scripting

parent shell pid

hi folks can any suggest me how to get a parent processid in the script if i am executing this in the script vi myscript.sh echo "parent shell pid"$$ sh myscript.sh but when i am executing this i am getting a new pid(actually that is the child pid) whenever i am executing this... (4 Replies)
Discussion started by: maheshwin
4 Replies

8. Shell Programming and Scripting

KILL PID, intern should kill another PID.

Hi All, In my project i have two process runs in the back end. Once i start my project, and execute the command ps, i get below output: PID TTY TIME CMD 9086 pts/1 0:00 ksh 9241 pts/1 0:02 java 9240 pts/1 0:00 shell_script_bg java with 9241 PID is the main... (4 Replies)
Discussion started by: rkrgarlapati
4 Replies

9. UNIX for Dummies Questions & Answers

Session PID & socket connection pid

1. If I use an software application(which connects to the database in the server) in my local pc, how many PID should be registered? Would there be PID for the session and another PID for socket connection? 2. I noticed (through netstat) that when I logged in using the my software application,... (1 Reply)
Discussion started by: pcx26
1 Replies

10. Programming

printing ppid,child pid,pid

question: for the below program i just printed the value for pid, child pid and parent pid why does it give me 6 values? i assume ppid is 28086 but can't figure out why there are 5 values printed instead of just two! can someone comment on that! #include<stdio.h> #define DIM 8 int... (3 Replies)
Discussion started by: a25khan
3 Replies
Login or Register to Ask a Question