Kill a process from parent shell within a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Kill a process from parent shell within a shell script
# 1  
Old 02-09-2010
Kill a process from parent shell within a shell script

Hi, I am looking for a solution for the following problem:

Im Using tcpdump within a shellskript started in a subshell by using brackets:
Code:
( /usr/sbin/tcpdump -i ... -c 1 )

  • - I want the outout of tcpdump saved in a variable
  • - Than tcpdump-Process in the Subshell should be killed
  • - and I want to use the variable in the parentshell for further steps of the skript

I hope you understand the circumstance and thanks in advance.

2retti

Last edited by 2retti; 02-09-2010 at 05:01 AM.. Reason: Formating
# 2  
Old 02-09-2010
something like:
Code:
RET=`/usr/sbin/tcpdump -i ... -c 1`
echo $RET

notice the ` instead of '
# 3  
Old 02-09-2010
Quote:
Originally Posted by redhead
something like:
Code:
RET=`/usr/sbin/tcpdump -i ... -c 1`
echo $RET

notice the ` instead of '
The Problem is, this works only if the tcpdump gets an Output.
Due to the given parameters of tcpdump it is possible that there is no output and so tcpdump is listing and listing..... Thats the reason why i need the possiblity to kill the process.
# 4  
Old 02-09-2010
great way of solving the issue without a subshell.
# 5  
Old 02-09-2010
Then use a subshell where you can kill the tcpdump, but don't put your tcpdump in a subshell : a subshell can't return any value to its parent process.
# 6  
Old 02-09-2010
Quote:
Originally Posted by frans
Then use a subshell where you can kill the tcpdump, but don't put your tcpdump in a subshell : a subshell can't return any value to its parent process.
Thanks, but I have no idea how this might look like. Can you give me a short explanation/example?
# 7  
Old 02-09-2010
Dependends on how you want to kill the process : by a user entry, after a certain delay...
you can put in your script BEFORE the call to tcpdump a part of code like
Code:
(   read -p "press enter to stop the process" # for an user entry
    sleep 5m # waits 5 minutes (can be seconds (default) , hours, days...)
    killall tcpdump # or something with pkill (see man pkill)
) &

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

System should not kill the child process when parent id is 1

HI i would like to know how i can simulate a shell scripts for my requirement. example Server name child Process id Parent Process id Vpesh 16013 15637 Server name child Process id Parent Process id Vpesh 16014 15637 Server name child... (1 Reply)
Discussion started by: vpesh
1 Replies

3. Shell Programming and Scripting

shell script to find a process by name and kill it

hi, Am a newbie to unix and wasnt able to write script to my requirement. I need a shell script, which should find a process by name and kill it. For eg: let the process name be "abc". I have different processes running by this name(abc), so should kill them all. Condition would be: if... (7 Replies)
Discussion started by: fop4658
7 Replies

4. Shell Programming and Scripting

Cron job and shell script to kill a process if memory gets to high

Hello, I'd like to set a cron job that runs a shell script every 30 minutes or so to restart a java based service if the memory gets above 80%. Any advice on how to do this? Thanks in advance! - Ryan (19 Replies)
Discussion started by: prometheon123
19 Replies

5. UNIX for Dummies Questions & Answers

Kill Duplicated Process by shell in crontab

Hi! I need your help, please. I'm in AIX node and sometimes listener process from an oracle instance gets duplicated, i mean that it get spawned a second listener process. As we can't apply changes to the databases on this months, i want to build a shell that can identify the second... (6 Replies)
Discussion started by: Pactows
6 Replies

6. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

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)
Discussion started by: vizz_k
2 Replies

7. Shell Programming and Scripting

shell script to kill process with respect to terminal

Hi, I've a script which kills all process, but i need a script shell script(sh), where it'll kill process on that particular terminal. below is example TY=`tty` for P in $TY do `kill -9 $P 2>/dev/null`; done echo "test process killed" break ... (3 Replies)
Discussion started by: asak
3 Replies

8. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

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

10. Shell Programming and Scripting

How to Run a shell script from Perl script in Parent shell?

Hi Perl/UNIX experts, I have a problem in running a shell script from my perl script (auto.pl). I run the perl script using perl auto.pl from the shell prompt The shell script picks the files in "input" folder and procesess it. The shell script blue.sh has this code. export... (16 Replies)
Discussion started by: hifake
16 Replies
Login or Register to Ask a Question