is there a universal way of getting the children of a particular process? i'm looking for a solution that works across different OSes...linux, aix, sunos, hpux.
i did a search online and i kept finding answers that were specific to Linux..i.e. pstree.
i want to be able to specify a process ID and then have the command spit out all its children processes. is this possible?
Check the man page for the ps utility -o option. The names used for various fields in the output may vary from system to system, but there should be heading like pid, ppid, and command OR PID, PPID, and CMD. Using those options, you can use something like (using a BSD-based ps as an example):
to get a list of all processes on your system showing its parent process ID, its process ID, and its command name and arguments. And to find all of the children of a given process ID, you could use:
where pid is the process ID of the process whose children you want to find.
If you want to find all of a process' un-orphaned descendants you could use an awk script instead of grep to create a tree of children, grandchildren, great-grandchildren, ... for all processes with a given process ID as a parent recursively. (Unfortunately, any process that has been orphaned, will have PPID 1 with no way to tie it back to its birth-parents.)
This User Gave Thanks to Don Cragun For This Post:
I usually have taken -e not -A for portable ps.
HP-UX needs environment variable UNIX95 to take the -o option.
If your pid is 4711 then a portable command to find its children is
Last edited by MadeInGermany; 06-02-2016 at 06:27 AM..
This User Gave Thanks to MadeInGermany For This Post:
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)
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)
I have a parent process which will start 36 child process. This I achieved by using the 'for loop'.
In Parent.sh:-
./Child.sh <arg1> <arg2> ... &
If I execute "ps -ef | grep Child.sh", I can see 72 child processes running at the background. I mean I can see the duplicate of each process.
... (2 Replies)
Hi
I am trying to see if there are some options in ps command or if there is a shell script which basically shows you all the processes spawned by a parent process , then all the processes of its child processes and so on down the hierarchy may be like a tree structure. It might be a generic... (6 Replies)
Hello,
How many child processes are actually created when running this code ?
#include <signal.h>
#include <stdio.h>
int main () {
int i ;
setpgrp () ;
for (i = 0; i < 10; i++) {
if (fork () == 0) {
if ( i & 1 ) setpgrp () ;
printf ("Child id: %2d, group: %2d\n",... (1 Reply)
Hello,
How many child processes are actually created when running this code ?
#include <signal.h>
#include <stdio.h>
int main () {
int i ;
setpgrp () ;
for (i = 0; i < 10; i++) {
if (fork () == 0) {
if ( i & 1 ) setpgrp () ;
printf ("Child id: %2d, group: %2d\n", getpid(),... (0 Replies)
Hello.
I have a global function name func1() that I am sourcing in from script A. I call the function from script B. Is there a way to find out which script called func1() dynamically so that the func1() can report it in the event there are errors?
Thanks (2 Replies)
Hello all, I am trying to create n child processes and control them from a parent process; say make child 3 print its pid and then child 5 do the same and some other stuff. Is there a way to accomplishing this after all the child processes are created via a call to fork().
Thank you,
FG (23 Replies)
I don't follow what these are...
this is what my text says...
"When a process is started, a duplicate of that process is created. This new process is called the child and the process that created it is called the parent. The child process then replaces the copy for the code the parent... (1 Reply)