kill login


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers kill login
# 1  
Old 01-08-2002
kill login

As a normal user, is it advised to logout the current session using kill command as

kill -9 -1 ?

I have created an action on my frontpanel which does this and I use this as an alternative way to logout of the current session. Will continuing to do like this affect the performance?
sskb
# 2  
Old 01-08-2002
That will kill every process owned by the user, not just every process for the current session. If that's what you want, it's fine.

But you don't want to do that as root. Smilie
# 3  
Old 01-09-2002
Personally, I don't like to use kill -9 right away. -9 (SIGKILL), drops the process in it's tracks, and doesn't give it a chance to save any work and exit gracefully. You will start leaving lots of old temp files around too...
I suggest starting with something like kill -1 (SIGHUP - the hang up signal), then perhaps sleeping for 3 seconds, sending kill -2 or kill -15, THEN kill any stubborn scripts with kill -9.

I can provide a short example if you'd like...
# 4  
Old 01-09-2002
Yes LivinFree, I would definitely like to have one. And I was trying to duplicate the button ExitSession on the frontpanel.
sskb
# 5  
Old 01-10-2002
Here's one that should kill all processess owned by a given user:
Code:
#!/bin/sh
if [ "$#" = "1" ]; then
        user="$1"
else
        echo "\nUsage: `basename $0` user_to_kill \n"
        exit 1
fi
if [ "$user" = `whoami` ]; then
        echo "\nI am not going to kill me.\n"
        exit 1
fi
if [ "$user" = "root" ]; then
        echo "\nI am not going to kill root.\n"
        exit 1
fi
if [ -z "`ps -ef|grep ^$user`" ]; then
        echo "\nI do not see \"$user\" logged in\n"
        exit 1
fi

# Below are some loops to try to "hang them up", then
# try to terminate their sessions, then flat out
# kill them.
kill_cmd="sudo kill"

for each1 in `ps -ef | grep "^$user" | awk '{print $2}'`
        do
                $kill_cmd -1 $each1
        done
sleep 1
for each15 in `ps -ef | grep "^$user" | awk '{print $2}'`
        do
                $kill_cmd -15 $each15
        done
sleep 1
for each9 in `ps -ef | grep "^$user" | awk '{print $2}'`
        do
                $kill_cmd -9 $each9
        done
echo "\nDie, $user !  \n"

So first I check to make sure I'm not killing me, root, and I make sure the user has processes running. Then I use sudo to allow me root access to kill a process that is not mine. Then kill away! If you want something to kill your own processes, you'd have to trap the signals, so they don't kill the script before it finishes:
Code:
#!/bin/sh
trap '' 1 2 15
my_procs=$(ps -ef | grep ^`whoami`| awk '{print $2}')
kill -1 $my_procs >/dev/null 2>&1
kill -15 $my_procs >/dev/null 2>&1
sleep 5
# Goodnight
kill -9 $my_procs >/dev/null 2>&1

This isn't the best code for this, but it is effective, in a pinch... hopefully, it'll give you some ideas of killing "lightly" first, then kill -9 later...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Can adding to a new group be effective in current login environment without re-login?

Hey folks, When a user is added to a new group, the user has to be log out and log in again to make the new group effective. Is there any system command or technique to refresh user group ID update without re-login? I am not talking about to use "login" or "su -l" commands which can only make... (2 Replies)
Discussion started by: hce
2 Replies

2. Shell Programming and Scripting

Kill an specific process ID using the KILL and GREP commands

Good afternoon I need to KILL a process in a single command sentence, for example: kill -9 `ps -aef | grep 'CAL255.4ge' | grep -v grep | awk '{print $2}'` That sentence Kills the process ID corresponding to the program CAL255.4ge. However it is possible that the same program... (6 Replies)
Discussion started by: enriquegm82
6 Replies

3. Solaris

Cannot kill a process with kill -9

Hello everyone, I have a process that I want to kill. I have tried kill-9 PID but it doesn't work. I have tried preap PID but it doesn't work too. The parent of my process is the process whose PID is 1, so I can't kill it. My OS is a Solaris 9. Can anyone help me understand what's going... (3 Replies)
Discussion started by: adilyos
3 Replies

4. Linux

Kill a process without using kill command

I want to Kill a process without using kill command as i don't have privileges to kill the process. I know the pid and i am using Linux 2.6.9 OS. (6 Replies)
Discussion started by: sudhamacs
6 Replies

5. Shell Programming and Scripting

Kill a process without using kill command

Sorry, posted the question in other forum. (0 Replies)
Discussion started by: sudhamacs
0 Replies

6. UNIX for Advanced & Expert Users

Diff b/n kill and kill -9

Hi, I have a process with say pid x. What is the difference b/n kill x and kill -9 x in unix Thanks Ammu (2 Replies)
Discussion started by: ammu
2 Replies

7. Programming

kill(0,-9) don't kill the process

Hi all i have simple c program , when i wish to kill the app im using kill(0,-9) , but it seams this command don't do any thing and the program. just ignore it . what im doing wrong here ? im using HP-UX ia64 Thanks (9 Replies)
Discussion started by: umen
9 Replies

8. UNIX for Dummies Questions & Answers

not able to kill find with kill -9

Hello everyone I am using HP Ux and had run a find command. Now I am trying to kill it with kill or kill -9 but it is not getting killed and still running. Any clues ? Thanks Sidhu (5 Replies)
Discussion started by: Amardeep
5 Replies

9. UNIX for Advanced & Expert Users

When kill doesnt work, how to kill a process ?

Hi All, I am unable to kill a process using kill command. I am using HP-UX system. I have tried with kill -9 and i have root privilages. How can i terminate this daemon ? ? ? Regards, Vijay Hegde (3 Replies)
Discussion started by: VijayHegde
3 Replies

10. Programming

do you believe X-application will "kill" the CDE and come back to login dialog

1 . Thanks you for reading the letter 2 . I have programe a X-application .Sometimes, I run it from terminal of CDE ,it "kill" the CDE and I meet the login dialog . I debug it . I find that the SIGHUP caused the X-app died .I do not run it from terminal of CDE ,I run it "click button" from panel ,... (3 Replies)
Discussion started by: chenhao_no1
3 Replies
Login or Register to Ask a Question