![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Parent child Relation !! using awk/sed ??? | varungupta | UNIX for Advanced & Expert Users | 0 | 01-29-2008 10:24 AM |
| Parent/Child Processes | yoi2hot4ya | Shell Programming and Scripting | 2 | 05-31-2006 10:27 AM |
| parent and child process question? | tosa | High Level Programming | 0 | 02-16-2005 11:04 AM |
| How hard can it be? ps child/parent | velde046 | Filesystems, Disks and Memory | 2 | 05-25-2002 01:36 PM |
| what are parent and child processes all about? | xyyz | UNIX for Dummies Questions & Answers | 1 | 04-26-2002 12:53 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
kill parent and child
Hello all,
I have gone through the search and looked at posting about idle users and killing processes. Here is my question I would like to kill an idle user ( which I can do) but how can I asure that all of his process is also killed whit out tracing his inital start PID. I have tried this on a solaris 8 system but, I seem to make the child process a zombie or hang because of what he was doing. Is there a clean way to do this? Thanks |
| Forum Sponsor | ||
|
|
|
|||
|
Thanks Perderabo,
What you suggested works great. But I did not fully explain myself. I have a guest account in which guest can use to log on to the server. But some guest do not log off thus the problem. I just want to kill only the select login in. Here is a print out of who -uH NAME LINE TIME IDLE PID COMMENTS guest pts/5 Jan 9 08:11 2:48 10842 (cic2) guest pts/6 Jan 9 10:44 0:02 11159 (cic4) guest pts/7 Jan 9 08:56 0:35 11039 (cic65) As per you suggestion I would use kill -9 -1 10842 But this will kill all users that are login. But I don't want to kill all login. Just guest at pts/5 from machine "cic2". I have looked at the man pages for kill but it does seem to talk about the addtional "-1" after kill -9. Thanks again |
|
|||
|
Re: kill parent and child
Quote:
Code:
#!/bin/ksh
# This script will kill all the child process id for a given pid
#Store the current Process ID
CURPID=$$
# This is process id, parameter passed by user
ppid=$1
if [ -z $ppid ] ; then
echo No PID given.
exit;
fi
arraycounter=1
while true
do
FORLOOP=FALSE
# Get all the child process id
for i in `ps -ef| awk '$3 == '$ppid' { print $2 }'`
do
if [ $i -ne $CURPID ] ; then
procid[$arraycounter]=$i
arraycounter=`expr $arraycounter + 1`
ppid=$i
FORLOOP=TRUE
fi
done
if [ "$FORLOOP" = "FALSE" ] ; then
arraycounter=`expr $arraycounter - 1`
## We want to kill child process id first and then parent id's
while [ $arraycounter -ne 0 ]
do
kill -9 "${procid[$arraycounter]}" >/dev/null
arraycounter=`expr $arraycounter - 1`
done
exit
fi
done
## Kill Parent ID
kill -9 $CURPID
Last edited by oombera; 02-18-2004 at 04:52 PM. |
|||
| Google UNIX.COM |