kill process

I have a script ( run by user ) that can find some user dead process ( like below ) , then another script will kill all these process, however , I found that one of these process is the user self login process ( pid : 58741 ) , therefore , when the script try to kill these dead process , it may be kill the user login process , if it is the case , then the user will logout and DO NOT kill other process ( of course , the user is logged out , all user's command will be stopped ) , can advise if I want to make sure it can kill ALL process , what can I do ? thx

58741 <-- the user login process
82587
58412
47521
87934
25462

How do you determine what is a dead process? If you end up trying to kill your own login then you are using some pretty naff logic to determine a dead process.

You can resolve up the chain from the current process to the login process using the parent process id (ppid).