Sponsored Content
Top Forums Shell Programming and Scripting shell script for getting pid of spawn processes from shell Post 302309350 by sachin4sachi on Tuesday 21st of April 2009 04:53:12 PM
Old 04-21-2009
Quote:
Originally Posted by TonyFullerMalv
$! can be interpreted as run previous command again, depending on the shell, so is not PID related.

If I was killing off all the child processes I would do something like:
Code:
for PROC in `ps -ef | grep " $$ " | grep -v $0 | grep -v grep | awk '{ print $2 }'`; do
  if [ -n "${PROC}" -a ${PROC} -ne 1 ]; then
    kill $PROC
  fi
done

As far as getting child PIDs into an array I'll leave that for a more experienced scripting guru!
Thanks for the solution TonyFullerMalv
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

KORN Shell - Spawn new shell with commands

I want to be able to run a script on one server, that will spawn another shell which runs some commands on another server.. I have seen some code that may help - but I cant get it working as below: spawn /usr/bin/ksh send "telnet x <port_no>\r" expect "Enter command: " send "LOGIN:x:x;... (2 Replies)
Discussion started by: frustrated1
2 Replies

2. Shell Programming and Scripting

Need to know rhe PID for the Shell Script running

I have a Shell Scritp named "Statistics" which has a Infinate Wille Loop Running I want to restart this Srcipt "Statistics" when i try to run other srcipt Ex "ABC" so i want to kill the "Statistics" script in "ABC" so for this I what to know the PID for that Script "Statistics" which is... (7 Replies)
Discussion started by: pbsrinivas
7 Replies

3. Shell Programming and Scripting

Shell script creating too many processes.

I have a shell script that I am running every 60 seconds, but it is creating this process to the point that it is causing the server to perfrom poorly. Below is my script, what can I change to prevent this? while true do java -classpath .....( all my classes here) >/dev/null 2>&1 ... (3 Replies)
Discussion started by: Miller_K
3 Replies

4. AIX

Having problem with executing shell script to get the pid details!

Hello Everyone, I am new to shell scripting and also i am very new to AIX machine I have a question. I have shell script which contains the follwing "ps -e |grep $1 echo $2" i run this schell script by doing this ./startSehllscript 3444 passed with two parameters . Accroiding my... (4 Replies)
Discussion started by: swati
4 Replies

5. UNIX for Dummies Questions & Answers

Bash: Regulating the number of processes a script can spawn

I've been working on some scripts in which I spawn some background processes. I'd like to be able to limit the number of processes, but have my script spawn additional processes as previous tasks finish. So, let's say I have 20 tasks to complete. Any given task could take from 1 to 10 minutes. ... (7 Replies)
Discussion started by: treesloth
7 Replies

6. Shell Programming and Scripting

Help with spawn.. newbie to shell

Hi, I have a problem with the spawn execution with expect.. i have done the code for expect in a separate file and i am calling the this execution from the bash script.. as given below.. -bash-4.1$ cat main.sh #!/usr/bin/bash ./spawn.exp ========================== -bash-4.1$ cat... (2 Replies)
Discussion started by: satishkumar432
2 Replies

7. Shell Programming and Scripting

Spawn sftp and Shell commands

Hi everyone, I'm no killer in shell scripting, that is why I've searched and found a little script that explained how to do what I wanted to do : a FTP transfer from distant servers. I adapted it cause as such, it didn't work. As I needed to do some very simple shell commands (erase and... (2 Replies)
Discussion started by: mederik
2 Replies

8. Shell Programming and Scripting

Wait for one processes to complete in a shell script

Let's say I start process A.sh, then start process B.sh. I call both of them in my C.sh How can I make sure that B starts its execution only after A.sh finishes. I have to do this in loop.Execution time of A.sh may vary everytime. It is a parameterized script. (17 Replies)
Discussion started by: rafa_fed2
17 Replies

9. Shell Programming and Scripting

Help with shell script handling processes

Hello I have a file which has around 120 lines of commands. I am trying to write a shell script like which reads the 'command' file and executes line by line with some additional (common argument) with maximum 6 commands active at a time. Each of these commands when executed takes time... (5 Replies)
Discussion started by: JackyShane_36
5 Replies

10. Shell Programming and Scripting

Shell script to report file size, pid and also kill the process

Hi All, Looking for a quick LINUX shell script which can continuously monitors the flle size, report the process which is creating a file greater than certain limit and also kill that process. Can someone please help me on this? (4 Replies)
Discussion started by: vasavimacherla
4 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 08:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy