Visit Our UNIX and Linux User Community

How can I get parent process program name?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I get parent process program name?
# 1  
Old 05-28-2012
How can I get parent process program name?


I have 2 script on AIX server.
The child script is called by parent script.
For example:
The parent script full name is

, which calls


I want to get the parent program name with full path name (i.e. /home/op/def/parent.spt),
in /home/op/abc/child.spt.
It is because of both of them are not have the following statement:


it make the child script cannot get the parent process program name and path name via ps command.

Is there any other method to get the parent process program name?
If cannot , Is there any other method to get the parent process program name path name?

thank you very much

Last edited by Scrutinizer; 05-28-2012 at 08:57 AM.. Reason: Give more detail information - mod: code tags
# 2  
Old 05-28-2012
PP_ID=`echo $PPID`
for PS_DT in `ps -ef`
PS_ID=`echo $PS_DT|tr -s " "|cut -d" " -f3`
if [ $PS_ID -eq $PP_ID ]; then
PS_NAME=`echo $PS_DT|tr -s " "|cut -d" " -f9`
echo $PS_NAME
exit 1

# 3  
Old 05-28-2012
/home/op/abc/child.spt "`ps -ef|awk '$2=='$$'{print $NF}'`"

echo "this is parent process name -> $1"

# 4  
Old 05-28-2012
because of missing #!/bin/ksh, the process file name cannot found in ps output, so I want to find other method to do so.

Previous Thread | Next Thread
Test Your Knowledge in Computers #954
Difficulty: Easy
Boot sector viruses specifically target the boot sector and/or the Master Boot Record (MBR) of the infected host's hard disk drive, solid-state drive, or removable storage media (flash drives, floppy disks, etc.).
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Control from UNIX script is not returning to the Parent program

Hi All, My program flow is as below Windows batch -- > Cygwin batch --> zsh script There are multiple Cygwin batch scripts that are called from Windows batch file . But when i am executing the first cygwin batch script the control goes to the zsh file and executes and stoping from... (1 Reply)
Discussion started by: Hypesslearner
1 Replies

2. Programming

Find parent process (not process ID)

Hi: I have a program written in FORTRAN running on AIX platform. It is because missing of documentation and without root password, therefore we want to modify the program so that we can find out which script/program that call this FORTRAN program. I have google for few days, all of them are... (3 Replies)
Discussion started by: cstsang
3 Replies

3. 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

4. Emergency UNIX and Linux Support

signal between parent process and child process

Hello, everyone. Here's a program: pid_t pid = fork(); if (0 == pid) // child process { execvp ...; } I send a signal (such as SIGINT) to the parent process, the child process receive the signal as well as the parent process. However I don't want to child process to receive the... (7 Replies)
Discussion started by: jackliang
7 Replies

5. Shell Programming and Scripting

[KSH/Bash] Starting a parent process from a child process?

Hey all, I need to launch a script from within 2 other scripts that can run independently of the two parent scripts... Im having a hard time doing this, if anyone knows how please let me know. More detail. ScriptA (bash), ScriptB (ksh), ScriptC (bash) ScriptA, launches ScriptB ScirptB,... (7 Replies)
Discussion started by: trey85stang
7 Replies

6. Shell Programming and Scripting

How to make the parent process to wait for the child process

Hi All, I have two ksh script. 1st script calls the 2nd script and the second script calls an 'C' program. I want 1st script to wait until the 'C' program completes. I cant able to get the process id for the 'C' program (child process) to make the 1st script to wait for the second... (7 Replies)
Discussion started by: sennidurai
7 Replies

7. UNIX for Dummies Questions & Answers

parent process

I need to kill all the processes of user "release" on system "PROterm" or the parent process for the user I did this ps -ef | grep PROterm | grep release i got release 2900014 2961494 0 12:19:44 pts/3 0:00 PROterm release 3264694 2900014 0 12:19:44 - 0:00 PROterm if i... (7 Replies)
Discussion started by: ajit.yadav83
7 Replies

8. UNIX for Dummies Questions & Answers

parent process in unix

hello i am not a unix programmer but i need to solve a particular problem using unix. suppose i have a user XYZ logged on to a system called ABC. i want to get the parent process id for the user and kill it i am using ps -ef | grep XYZ | grep ABC it returns me all the processes for... (2 Replies)
Discussion started by: ajit.yadav83
2 Replies

9. UNIX for Advanced & Expert Users

How can i get the parent process only?

Hello, I'm running one script every night and that's kick off through cron jobs. Inside the script i'm checking whether my script is already running or not. I'm using following command to check whether is running or not. ps -eaf | grep "test_PID.ksh" | grep -v "grep test_PID.ksh"... (5 Replies)
Discussion started by: nirav_soni
5 Replies

10. Shell Programming and Scripting

how to find the chid process id from given parent process id

how to find the chid process id from given parent process id.... (the chid process doesnot have sub processes inturn) (3 Replies)
Discussion started by: guhas
3 Replies

Featured Tech Videos