Sponsored Content
Top Forums Shell Programming and Scripting Preparing a list of spawned processes Post 302464869 by huskie69 on Thursday 21st of October 2010 07:24:45 AM
Old 10-21-2010
Preparing a list of spawned processes

Hi All

I'm currently trying to develop a script which will find the child processes of a process ID already passed to the script.

I then need the script to look for spawned processes of these child processes and so on until it can't find any more.

For example

At the moment, I have to manually do this on the server -

Code:
ps -ef | grep 7133 | grep -v grep
USER  7134  7133  0 08:12:38 ?        0:19 child process 1
USER 7133  7128  0 08:12:38 ?        0:00 main processes

I need to find child/spawned processes of 7133 so straight away, I need to grep for 7134.

Code:
ps -ef | grep 7134 | grep -v grep
USER  7137  7134 0 08:12:38 ?        0:19 child process 2
USER 7134  7133  0 08:12:38 ?        0:00 child process 1

Next, I get 7137

You get the idea. There are also cases where one parent process spawns multiple child processes and I need to be able to trace these down individually.

I then need to build a list of all these process ids so that I can kill -9 them.

I've build a script part way and thought I'd be able to assign the processes IDs to a variable using something like this:

Code:
        REP1=$(ps -ef | grep report | grep -v grep | awk '{print $2}')
        REP2=$(ps -ef | grep $REP1 | grep -v grep | awk '{print $2}')
        REP3=$(ps -ef | grep $REP2 | grep -v grep | awk '{print $2}')
        REP4=$(ps -ef | grep $REP3 | grep -v grep | awk '{print $2}')
        REP5=$(ps -ef | grep $REP4 | grep -v grep | awk '{print $2}')

This has failed to work because of multiple processes numbers appearing on the same line.

The script is using KSH.

Any help would be greatly appreciated (as I'm quickly running out of hair!)

TIA
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Is there any cmd to kill a process including its childs ( or sub processes spawned by

Dear Unix Gurus, Here is my query. If i start a script,it inturn calls many other scripts ..and most of them continue to run in parallel. Suppose,if i want to stop my script for some reason,i need to kill -9 each of the processes running.It becomes clumsy if the sub processes r more. ... (15 Replies)
Discussion started by: gvsreddy_539
15 Replies

2. Linux

How to receive results from processes spawned on external machines using SSH

I am trying to get the number of cpus on a farm of linux boxes (about 100 of them) by 'sshing' to each of them and checking their /proc/cpuinfo file. So I have a local script localscript.sh on each of those 100 machines which retrieves the number of cpus in it by using its /proc/cpuinfo file.... (1 Reply)
Discussion started by: waavman
1 Replies

3. Programming

how to get list of processes

Hi, How can I get a list of all the running processes, in C? (13 Replies)
Discussion started by: yaron
13 Replies

4. SuSE

List of processes/ which ones to stop

Hi there, I've install a testserver with SLES 11.0! I'll install/test XEN + WebServer not all things at the moment! In a first time, I'd like to stop all unuse processes... but I don't understand all processes! As someone a list of all processes with his signification and which should/could... (3 Replies)
Discussion started by: hiddenshadow
3 Replies

5. Shell Programming and Scripting

Need to list 3 days old processes

ps -xfu <user name> this command line will list all the process currently running for <user name>. I need to filter this output. I need all the process which are running for more than 3 days(excluding demon/sys process) . The list should include PID, PPID, STIME, process/command. I am using... (20 Replies)
Discussion started by: Sriranga
20 Replies

6. UNIX for Dummies Questions & Answers

List processes that are running on other hosts

Hi: How to list processes from all hosts, as opposed to the one you are working at? "ps ux" appears to list processes of the user on a single host only. Thanks. N.B Phil (5 Replies)
Discussion started by: phil518
5 Replies

7. Solaris

Get list of running network processes

Hello All I am trying to get a list of process or applications runninging on the network only. I should emphasize that im not interested in the application or process if its not using the network. I tried the good old netstat comand, but im not able to figure out how to list the running... (8 Replies)
Discussion started by: busi386
8 Replies

8. UNIX for Advanced & Expert Users

Kill a list of processes

I am trying to kill a list of processes. I have found these two ways to list a group of process id's on a single line. How would I go about killing all of these processes all on one line? $ ps aux | grep 6243 | grep "a.out" | awk '{printf "%s ",$2}'ps aux | grep 6243 | grep "a.out" | awk... (8 Replies)
Discussion started by: cokedude
8 Replies

9. UNIX for Advanced & Expert Users

List all background processes

How do I list the process in a Unix based system which are running in background? The following are options that I'm aware of, but they may not be appropiate. a. using ps -ef , and getting records of processes for which STATUS='S'(uninterruptible sleep) b. using jobs -l, and filtering... (5 Replies)
Discussion started by: kumarjt
5 Replies

10. Shell Programming and Scripting

List processes using my memory

Here is the output of top command So you see 99% of memory is in use -> Mem: 66005468k total, 65662548k used, How can I find out all processes consuming this 99% memory in descending order of consumption i.e. starting with processes eating more memory. I need the total of the output to... (3 Replies)
Discussion started by: mohtashims
3 Replies
ZGREP(1)                                                      General Commands Manual                                                     ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 11:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy