How to kill processes under UNIX SVR4 ?

How to kill processes under UNIX SVR4 ?

Post by Thierry Ruell » Tue, 07 Jan 1997 04:00:00



How to kill processes under UNIX SVR4 ?

When a terminal is disconnected from a UNIX system, the attached process
and all child processes have to be killed.

This should happen automatically by UNIX but this is not always the case.

I have therefore written a function which periodically verifies if the
process is still attached to its parent.

I have used the function GETPPID who returns the process ID of the parent
process, wich is 1 if the parent does not exist anymore.
If the result is yes 1, the program must exit.

This method is wrong with a SEQUENT and RM400 SIEMENS where we have found
normal processes with PPID = 1. (It seems that each UNIX session begins
with PID=1 instead of a circular numbering for all processes.)

Has someone an idea for a universal method to solve this problem ?

Thanks for your help and best wishes for a happy new year.


 
 
 

How to kill processes under UNIX SVR4 ?

Post by Thierry Ruell » Fri, 10 Jan 1997 04:00:00


How to kill processes under UNIX SVR4 ?

When a terminal is disconnected from a UNIX system, the attached process
and all child processes have to be killed.

This should happen automatically by UNIX but this is not always the case.

I have therefore written a function which periodically verifies if the
process is still attached to its parent.

I have used the function GETPPID who returns the process ID of the parent
process, wich is 1 if the parent does not exist anymore.
If the result is yes 1, the program must exit.

This method is wrong with a SEQUENT and RM400 SIEMENS where we have found
normal processes with PPID = 1. (It seems that each UNIX session begins
with PID=1 instead of a circular numbering for all processes.)

Has someone an idea for a universal method to solve this problem ?

Thanks for your help and best wishes for a happy new year.



 
 
 

How to kill processes under UNIX SVR4 ?

Post by Pete For » Fri, 10 Jan 1997 04:00:00



> How to kill processes under UNIX SVR4 ?

> When a terminal is disconnected from a UNIX system, the attached process
> and all child processes have to be killed.

> This should happen automatically by UNIX but this is not always the case.

> I have therefore written a function which periodically verifies if the
> process is still attached to its parent.

> I have used the function GETPPID who returns the process ID of the parent
> process, wich is 1 if the parent does not exist anymore.
> If the result is yes 1, the program must exit.

> This method is wrong with a SEQUENT and RM400 SIEMENS where we have found
> normal processes with PPID = 1. (It seems that each UNIX session begins
> with PID=1 instead of a circular numbering for all processes.)

> Has someone an idea for a universal method to solve this problem ?

> Thanks for your help and best wishes for a happy new year.



This sounds like a bad idea - there are lots of processes likely to be
detached from their parents (background processes, daemons etc.).
Killing anything with a PPID of 1 is definitely bad; the 'init' process
is always (on all Unix systems I've used anyway) PID 1 and this starts
and maintains most of the system daemons that are ESSENTIAL for
operation.

You MIGHT be safe if you check that the process's UID is not 0 as well
as PPID=1, since really important processes will be run as root. I've
not checked this thoroughly be VERY careful...it may also still miss a
few things, where programs run suid root to do certain things.

Please don't blame me if the whole thing goes up in smoke...it sounds
like there's some fundamental problem if the processes are not being
killed as you expect them to be.
--
Pete Ford       Unix Sys. Admin.        Oxford University Computing Services
Phone: +44 1865 2~73266                 Look mum, a real job!
"I'm sorry but you need more help than I can give you over the phone"-
R. Letts
The above message represents my personal opinion; neither my employers,
nor any other organisation, is responsible for statements made therein

 
 
 

1. How can kill all child processes without killing parent process ?

: Hi all UNIX expert,

: I am now writing a shell script to kill all child processes of a
: particular process.  I have written the following
: script:

: ps -ef | grep o\\ra  | awk '{print $2}' | xargs kill

: where ora is the name of the parent process

: However, this shell script only kills out the parent process,
: Does anyone know how to kill all child process without
: killing that parent process ? Please advise !!! Many thanks !!!
: Have a nice UNIX day !!!

you will have to read all matching processes and only kill the last in the
chain by using PID and PPID; unfortunately we can not assume that the
child is the process with the highest PPID:
assume $2=PID , $3=PPID ( coming from   ps -ef | grep o\\ra  | grep -v grep )

{
        PID[ $2 ]=""
        PPID[ $3 ]=""

END{
# process ids which are also parents should be deleted
        for( pid in PPID ) if ( pid in PID ) delete PID[ pid ]
        for( pid in PID ) { do_whatever_you_like_on_your_own_risk( pid ) }
        }

function do_whatever_you_like_on_your_own_risk( param ){
        code...
        }

2. Ebook!!!

3. A method to kill process that cannot be killed even with `kill -9'.

4. Which soundcard should I use?

5. How to kill process which not killed by 'kill' ?

6. Alias Substitution in ksh/bash??

7. Accessing Process Control Block (PCB) in Digital UNIX 4.0D (SVR4)

8. i'm looking for short HOWTOs...

9. How to Kill Process and Its sub-process and its sub-process??

10. How to Kill a process and its sub-process and its sub-process at a time..

11. Unix SVR4 diskio statistics per process(es) ??

12. killing dead process, kill -9 doesn′t work

13. how to kill a process when kill -9 won't