Sponsored Content
Top Forums Shell Programming and Scripting Environment Variable Parent PID Post 302106756 by scotbuff on Monday 12th of February 2007 12:02:07 PM
Old 02-12-2007
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 make sure I was not missing something more elegant. As always, thanks in advance.
 

10 More Discussions You Might Find Interesting

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

2. UNIX for Dummies Questions & Answers

Passing environment variables to parent shells

Hi, I am using bash and need to run a set of tcsh scripts that set environment variables. Is there a way to do this? Any help greatly appreciated. (3 Replies)
Discussion started by: konndanley
3 Replies

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

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

Invoking commands in "parent" environment

The below shell script obtains a command and an alias from the user then appends the alias to the users ~/.aliases file. It is useful with cd commands and saves typing; instead of going cd /foo/bar/bonk/boo/what/whatelse/dir I create an alias something like "godir". It's not done and I will... (2 Replies)
Discussion started by: whosit1963
2 Replies

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

7. Shell Programming and Scripting

Get PID of a process into a variable

Hi All, I need to get the PID of a process which i ran in background into a variable echo $! gives me the PID of last background process but how to get this into a variable so that i can use "wait" command later in the script to make sure that this background process was done var = `echo... (5 Replies)
Discussion started by: firestar
5 Replies

8. Shell Programming and Scripting

Expand an environment variable in sed, when the variable contains a slash

I'm trying to make a sed substitution where the substitution pattern is an environment variable to be expanded, but the variable contains a "slash". sed -e 's/<HOME_DIRECTORY>/'$HOME'/'This gives me the following error: sed: -e expression #1, char 21: unknown option to `s'Obviously this is... (2 Replies)
Discussion started by: Ilja
2 Replies

9. Shell Programming and Scripting

How to export a variable from a subshell to the parent shell?

A not-too-ugly solution to this classic problem... #!/bin/bash mknod fifo p ( echo 'value' > fifo & ) VARIABLE=`cat fifo` rm fifo Whatdcha think? Good? No good? (9 Replies)
Discussion started by: vomv1988
9 Replies

10. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: mohtashims
3 Replies
getpid(2)							System Calls Manual							 getpid(2)

NAME
getpid(), getpgid(), getpgrp(), getpgrp2(), getppid() - get process, process group and parent process ID. SYNOPSIS
DESCRIPTION
These functions return process, process group and parent process IDs, as follows: Process group ID of the specified process. If pid is zero, the call applies to the calling process. Same result as Process group ID of the calling process. Process group ID of the specified process. If pid is zero, the call applies to the calling process. Same result as Process ID of the calling process. Parent process ID of the calling process. If the parent process is the initialization process (known as the call returns 1. Security Restrictions The system call is subject to compartmental restrictions. See compartments(5) for more information about compartmentalization on systems that support that feature. Compartmental restrictions can be overridden if the process possesses the privilege (PRIV_COMMALLOWED). Processes owned by the superuser may not have this privilege. Processes owned by any user may have this privilege, depending on system configuration. See privileges(5) for more information about privileged access on systems that support fine-grained privileges. RETURN VALUE
The functions return the following values: Successful completion. n is a nonnegative process ID, as described above. Failure: and only. is set to indicate the error. ERRORS
If or fails, is set to one of the following values: [EPERM] The current process and pid are not in the same session (see setsid(2)). [ESRCH] No process can be found corresponding to that specified by pid. AUTHOR
and were developed by HP, AT&T, and the University of California, Berkeley. SEE ALSO
exec(2), fork(2), setpgid(2), setsid(2), signal(5). STANDARDS CONFORMANCE
getpid(2)
All times are GMT -4. The time now is 11:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy