kill parent and child


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers kill parent and child
# 1  
Old 01-09-2003
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
# 2  
Old 01-09-2003
To kill absolutely every process owned by a non-root user, su to that user and then use:
kill -9 -1
# 3  
Old 01-09-2003
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
# 4  
Old 01-09-2003
I never said anything about "kill -9 -1 10842". The command is:
kill -9 -1
press the enter key after the -1. Do not append other integers to this command.

The -1 is pid. Look at the man pages again. I sure have in my man pages.

Since you want to kill only some of a user's processes, you will need to track them down. Maybe a command like "ps -ft pts/5" will help.
# 5  
Old 01-12-2003
Re: kill parent and child

Quote:
Originally posted by larry
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
I have used the following shell script to kill all child PID's for a given PID.

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

added code tags for readability --oombera

Last edited by oombera; 02-18-2004 at 08:52 PM..
sanjay92
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Kill Parent/ Child processes

I am trying to kill PIDs that are tied to a KSH "load_sqlplus" and I am using the below code LIST_PID=`ps -ef | grep -i "load_sqlplus" | grep -v grep | awk '{print $2}'` if ; then echo "Processes killed" "PID : " $LIST_PID kill -9 $LIST_PID else echo "Nothing to Kill" fi... (4 Replies)
Discussion started by: venky338
4 Replies

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

4. Homework & Coursework Questions

Need help with deleting childīs parent and child subprocess

1. The problem statement, all variables and given/known data: I need to make an program that in a loop creates one parent and five children with fork(). The problem i'm trying to solve is how to delete the parent and child of the childīs process. 2. Relevant commands, code, scripts,... (0 Replies)
Discussion started by: WhiteFace
0 Replies

5. Programming

To share fd between parent and child

i used function fork(). so i made two process. parent process accepted socket fd and writing to shared memory. then now. how can child process share parent's socket fd? is this possible? Thanks in advance (1 Reply)
Discussion started by: andrew.paul
1 Replies

6. UNIX for Dummies Questions & Answers

Kill child processes, when parent is "bash"

Consider this simple command line bash -c 'echo $$ ; sleep 10000'This will print the newly created bash PID and sleep for a long time. If I go to another terminal and do something like ps -flax | grep leepI'll see something like 501 92418 91910 0 0:00.00 ttys000 0:00.00 bash -c echo $$... (5 Replies)
Discussion started by: teras
5 Replies

7. UNIX for Advanced & Expert Users

Child Killing Parent

Hi all, I am writing a script which calls other third party scripts that perform numerous actions. I have no control over these scripts. My problem is, one of these scripts seems to execute and do what it is meant to do, but my calling / parent script always exits at that point. I need to... (4 Replies)
Discussion started by: mark007
4 Replies

8. Shell Programming and Scripting

Parent/Child Processes

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

9. Filesystems, Disks and Memory

How hard can it be? ps child/parent

:( Since I'm fairly new to the scene and don't have much experience in shell programming, I decided to check out the net for a useful script or two. What I'm looking for is a script that would let me enter a PID and then show the process tree associated with it. So it would display the (grand-)... (2 Replies)
Discussion started by: velde046
2 Replies

10. UNIX for Dummies Questions & Answers

what are parent and child processes all about?

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)
Discussion started by: xyyz
1 Replies
Login or Register to Ask a Question