Sponsored Content
Full Discussion: Another PID ?
Top Forums UNIX for Dummies Questions & Answers Another PID ? Post 302231553 by buffoonix on Tuesday 2nd of September 2008 03:11:15 PM
Old 09-02-2008
Many awk implementations also allow passing shell variables, either via the -v option, or as trailing argument (after the file to parse).
So you could probably avoid some quoting trouble by e.g.
Since you are on Solaris the awk there knowing this option might be in /usr/xpg4/bin
while the /usr/bin awk could be a little more dumb.
Code:
$ ps -ef | awk -v ppid=$PPID '$2==ppid {print $8}'

But I think you could further improve by setting up your own format instead of relying on -f
which may change between different ps implementations.
Just tell ps what fields you are interested in.
e.g.
Code:
cmd=`ps -e -o ppid= -o comm= | awk -v ppid=$PPID '$1==ppid {print $2}'`

Note, that this would only capture the command.
If you need the command line including arguments substitute -o comm= by -o args=.
Unfortunately, I haven't access to a Solaris box right now, and I don't know by heart.
So I may be wrong, but I think to remember that Solaris also has a pgrep command similar to that found on Linux (I would suggest to refer to man pgrep)
Another, often working way (except in C-shell compatibles (well except on FreeBSD yet where it even works in csh)) is to simply refer to $0 for the current shell, and $- for its arguments.
Then you also might be interested to note that Solaris has a ptree command
similar to pstree on Linux, which will list a process hierarchy tree that could be parsed.
And Solaris even has a rudimentary procfs with a set of accompanying p* commands (like ptree above).
As said, I am only recapitulating this without a system to verify at hands.
Therefore, please check the man pages.
 

10 More Discussions You Might Find Interesting

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

2. UNIX for Advanced & Expert Users

Pid=0

What OS does not use PID=0? is it FreeBSD? (0 Replies)
Discussion started by: nmajin
0 Replies

3. Shell Programming and Scripting

how to get PID only

The below command returns full line.How can i get only PID from this line ie 15794 from the below example (FI NY) nbswpsa52.ny.ficc.gs.com~ ->ps -ef | grep keepalive | grep -v keepaliveStub | grep -v swapback | grep -v grep ficctprd 15794 1 0 13:12:58 ? 0:01 keepalive (3 Replies)
Discussion started by: kotasateesh
3 Replies

4. UNIX for Dummies Questions & Answers

getting PID

Hi , I am trying to get the PID using the following command: $ /usr/ucb/ps -auwwwwx | grep java | grep Proceess | ptree PID or $ /usr/ucb/ps -auwwwwx | grep java | grep Proceess;ptree PID it is possible to get PID, such that I check whether any orphan process is running. solution... (0 Replies)
Discussion started by: Rakesh Bhat
0 Replies

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

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

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

8. UNIX for Dummies Questions & Answers

Get pid

Hello people, This question might seem to be a little naive but here it goes: I want to know the PID of a script that is running in the background. eg: There is a script called Data_Downloader.sh I am using the command: ps -ef | grep Data_Downloader.sh But I am getting the output as wrkarea... (9 Replies)
Discussion started by: Rajat
9 Replies

9. UNIX for Dummies Questions & Answers

PID value

name the process wit PID value 0? swapper or scheduler or both.... (3 Replies)
Discussion started by: karthi_g
3 Replies

10. Shell Programming and Scripting

Pid=$!

Hello, I would like to know what this command means? PID=$! what does "!" stand for? (5 Replies)
Discussion started by: googlietdr
5 Replies
PKILL(1)						    BSD General Commands Manual 						  PKILL(1)

NAME
pgrep, pkill -- find or signal processes by name SYNOPSIS
pgrep [-LSafilnoqvx] [-F pidfile] [-G gid] [-M core] [-N system] [-P ppid] [-U uid] [-c class] [-d delim] [-g pgrp] [-j jid] [-s sid] [-t tty] [-u euid] pattern ... pkill [-signal] [-ILafilnovx] [-F pidfile] [-G gid] [-M core] [-N system] [-P ppid] [-U uid] [-c class] [-g pgrp] [-j jid] [-s sid] [-t tty] [-u euid] pattern ... DESCRIPTION
The pgrep command searches the process table on the running system and prints the process IDs of all processes that match the criteria given on the command line. The pkill command searches the process table on the running system and signals all processes that match the criteria given on the command line. The following options are available: -F pidfile Restrict matches to a process whose PID is stored in the pidfile file. -G gid Restrict matches to processes with a real group ID in the comma-separated list gid. -I Request confirmation before attempting to signal each process. -L The pidfile file given for the -F option must be locked with the flock(2) syscall or created with pidfile(3). -M core Extract values associated with the name list from the specified core instead of the currently running system. -N system Extract the name list from the specified system instead of the default, which is the kernel image the system has booted from. -P ppid Restrict matches to processes with a parent process ID in the comma-separated list ppid. -S Search also in system processes (kernel threads). -U uid Restrict matches to processes with a real user ID in the comma-separated list uid. -d delim Specify a delimiter to be printed between each process ID. The default is a newline. This option can only be used with the pgrep command. -a Include process ancestors in the match list. By default, the current pgrep or pkill process and all of its ancestors are excluded (unless -v is used). -c class Restrict matches to processes running with specified login class class. -f Match against full argument lists. The default is to match against process names. -g pgrp Restrict matches to processes with a process group ID in the comma-separated list pgrp. The value zero is taken to mean the process group ID of the running pgrep or pkill command. -i Ignore case distinctions in both the process table and the supplied pattern. -j jid Restrict matches to processes inside jails with a jail ID in the comma-separated list jid. The value ``any'' matches processes in any jail. The value ``none'' matches processes not in jail. -l Long output. For pgrep, print the process name in addition to the process ID for each matching process. If used in conjunction with -f, print the process ID and the full argument list for each matching process. For pkill, display the kill command used for each process killed. -n Select only the newest (most recently started) of the matching processes. -o Select only the oldest (least recently started) of the matching processes. -q Do not write anything to standard output. -s sid Restrict matches to processes with a session ID in the comma-separated list sid. The value zero is taken to mean the session ID of the running pgrep or pkill command. -t tty Restrict matches to processes associated with a terminal in the comma-separated list tty. Terminal names may be of the form ttyxx or the shortened form xx. A single dash ('-') matches processes not associated with a terminal. -u euid Restrict matches to processes with an effective user ID in the comma-separated list euid. -v Reverse the sense of the matching; display processes that do not match the given criteria. -x Require an exact match of the process name, or argument list if -f is given. The default is to match any substring. -signal A non-negative decimal number or symbolic signal name specifying the signal to be sent instead of the default TERM. This option is valid only when given as the first argument to pkill. If any pattern operands are specified, they are used as regular expressions to match the command name or full argument list of each process. If the -f option is not specified, then the pattern will attempt to match the command name. However, presently FreeBSD will only keep track of the first 19 characters of the command name for each process. Attempts to match any characters after the first 19 of a command name will quietly fail. Note that a running pgrep or pkill process will never consider itself nor system processes (kernel threads) as a potential match. EXIT STATUS
The pgrep and pkill utilities return one of the following values upon exit: 0 One or more processes were matched. 1 No processes were matched. 2 Invalid options were specified on the command line. 3 An internal error occurred. COMPATIBILITY
Historically the option ``-j 0'' means any jail, although in other utilities such as ps(1) jail ID 0 has the opposite meaning, not in jail. Therefore ``-j 0'' is deprecated, and its use is discouraged in favor of ``-j any''. SEE ALSO
kill(1), killall(1), ps(1), flock(2), kill(2), sigaction(2), pidfile(3), re_format(7) HISTORY
The pkill and pgrep utilities first appeared in NetBSD 1.6. They are modelled after utilities of the same name that appeared in Sun Solaris 7. They made their first appearance in FreeBSD 5.3. AUTHORS
Andrew Doran <ad@NetBSD.org> BSD
August 9, 2013 BSD
All times are GMT -4. The time now is 01:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy