Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to stop running programs
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
PovMan
Guru
Guru


Joined: 30 Sep 2002
Posts: 375
Location: Australia

PostPosted: Sat Dec 06, 2003 12:24 am    Post subject: How to stop running programs Reply with quote

I figured this might be useful to someone.
You know how you can stop programs by pressing ctrl-z? well, this only works if you started the program from a terminal. So i added a few lines to my .bashrc
Put a few lines after the aliases that say
Code:
alias stop="kill -s 19"
alias cont="kill -s 18"

Now to stop a program, you first find out its PID with top or ps, and run 'stop <pidnumber>'. program is stopped. to continue the program just do 'cont <pidnumber>'.
I often use this on GRIP because it chews up all yer cpu when you want to emerge stuff :D

It would be really nice if xkill could send signals other than kill...
_________________
I am SPAM, hear me roar.
Before posting your own topic, try to answer at least one unanswered one.
Back to top
View user's profile Send private message
X
Apprentice
Apprentice


Joined: 30 Apr 2002
Posts: 192
Location: Lexington KY

PostPosted: Sat Dec 06, 2003 2:07 am    Post subject: Reply with quote

Hey, that's kinda cool. BTW, you can also use the pidof command to find the pid of something.
Code:

pidof bash
kill `pidof python` # Lews_therin adds that this kills ALL instances of python


Maybe it's a useful bit of knowledge... and useful with this tip.

You could even throw something like this in your .bashrc

Code:

bstop () {
        if [ -z $1 ]; then
                echo "No input."
        else
                kill -s 19 `pidof $1`
        fi
}
 
bcont () {
        if [ -z $1 ]; then
                echo "No input."
        else
                kill -s 18 `pidof $1`
        fi
}


And then just say
Code:
bstop xmms
bcont xmms


Cool.


Last edited by X on Sat Dec 06, 2003 2:40 am; edited 1 time in total
Back to top
View user's profile Send private message
Lews_Therin
l33t
l33t


Joined: 03 Oct 2003
Posts: 657
Location: Banned

PostPosted: Sat Dec 06, 2003 2:15 am    Post subject: Reply with quote

X wrote:
Hey, that's kinda cool. BTW, you can also use the pidof command to find the pid of something.
Code:

pidof bash
kill `pidof python`



What happens if you have multiple instances of a program running? With ps I will know what the pid is, depending on when I launched the program. Wouldn't that kill every instance of the program?
Back to top
View user's profile Send private message
X
Apprentice
Apprentice


Joined: 30 Apr 2002
Posts: 192
Location: Lexington KY

PostPosted: Sat Dec 06, 2003 2:37 am    Post subject: Reply with quote

Yes, it will affect every process with that name, I forgot to mention that. It doesn't kill though--it suspends.

Edit: Oh I see, you were talking about my examples. Yeah... they were just examples of the pidof command.
Back to top
View user's profile Send private message
ILikePi
n00b
n00b


Joined: 29 Nov 2003
Posts: 22
Location: Rhode Island, USA

PostPosted: Sat Dec 06, 2003 5:43 am    Post subject: Reply with quote

you should be able to use the name of the signal instead, which might help readability a bit. such as 'kill -STOP <pid>' and 'kill -CONT <pid>'.

also, processes in the "stopped" state are shown with a status of 'T' under the ps command:

Code:
  PID TTY      STAT   TIME COMMAND
25592 ?        S      0:00 [sshd]
25594 pts/0    S      0:00 -bash
25600 pts/0    T      0:01 pine
25601 pts/0    R      0:00 ps x

_________________
Keyboard not found.
Press F1 to continue.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum