[opensuse] I have a small script to run several programs - pidgin, thunderbird, skype - by one click. How can I close them by one click?
My script is #/bin/bash pidgin& skype& alltray thunderbird& dropbox start -i & -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
arygroup@gmail.com wrote:
My script is
#/bin/bash pidgin& skype& alltray thunderbird& dropbox start -i &
"man killall" should lead you to what you need. -- 葛斯克 愛德華 / 台北市八德路四段 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello, On Sun, 21 Mar 2010, arygroup@gmail.com wrote:
My script is
#/bin/bash pidgin& skype& alltray thunderbird& dropbox start -i &
==== some ideas, UNTESTED ==== #!/bin/bash PROGS=( "pidgin" \ "skype" \ "alltray thunderbird" \ "dropbox start -i" \ ) pids_to_kill=() killem() { sig=$1; shift; for pid in ${pids_to_kill[@]}; do kill "-$sig" $pid done exit $sig } trap "killem HUP" HUP trap "killem INT" INT trap "killem USR1" USR1 trap "killem TERM" TERM EXIT for prog in "${PROGS[@]}"; do $prog & pids_to_kill=( ${pids_to_kill[@]} $! ) done wait ==== HTH, -dnh -- No trees were destroyed in the sending of this message, however, a significant number of electrons were terribly inconvenienced. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 21/03/10 04:35, David Haller wrote:
Hello,
On Sun, 21 Mar 2010, arygroup@gmail.com wrote:
My script is
#/bin/bash pidgin& skype& alltray thunderbird& dropbox start -i &
==== some ideas, UNTESTED ==== #!/bin/bash PROGS=( "pidgin" \ "skype" \ "alltray thunderbird" \ "dropbox start -i" \ )
pids_to_kill=()
killem() { sig=$1; shift; for pid in ${pids_to_kill[@]}; do kill "-$sig" $pid done exit $sig }
trap "killem HUP" HUP trap "killem INT" INT trap "killem USR1" USR1 trap "killem TERM" TERM EXIT
for prog in "${PROGS[@]}"; do $prog & pids_to_kill=( ${pids_to_kill[@]} $! ) done wait ====
HTH, -dnh
I didn't read the kill manual, but I have a doubt. Is killing a program the same, as I close it in a legal way? -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sun, 2010-03-21 at 13:18 +0200, arygroup@gmail.com wrote:
I didn't read the kill manual, but I have a doubt. Is killing a program the same, as I close it in a legal way?
Depends on the program. "kill" is really one of the worst named programs anywhere. It should have been called something like "signal", because that is what it does - it sends a signal to a given process. The signal INT (2) is the one sent by a shell when you press ctrl-c for example. Most signals can be "caught" by an application, and many programs will catch the INT signal and do a controlled exit. Usually the same happens with the TERM signal, which is the default one sent by the kill command if you don't specify something else. The HUP signal is used by some applications to trigger a re-read of the configuration without having to restart. Postfix for example uses this Some signals can't be caught, for example SIGKILL (9). If that is sent to a process, it will exit immediately and no further instructions from it will be executed (with one exception, if the process is currently inside a kernel syscall it usually can't be interrupted, so the process will exit as soon as the syscall finishes). This should normally not be used except in extreme circumstances How a particular program behaves when a signal is sent to it should be described in the documentation. For modern kde and gnome applications, the intended method of sending commands to programs from scripts is with dbus. Anders -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 21/03/10 13:47, Anders Johansson wrote:
On Sun, 2010-03-21 at 13:18 +0200, arygroup@gmail.com wrote:
I didn't read the kill manual, but I have a doubt. Is killing a program the same, as I close it in a legal way?
Depends on the program.
"kill" is really one of the worst named programs anywhere. It should have been called something like "signal", because that is what it does - it sends a signal to a given process. The signal INT (2) is the one sent by a shell when you press ctrl-c for example.
Most signals can be "caught" by an application, and many programs will catch the INT signal and do a controlled exit. Usually the same happens with the TERM signal, which is the default one sent by the kill command if you don't specify something else.
The HUP signal is used by some applications to trigger a re-read of the configuration without having to restart. Postfix for example uses this
Some signals can't be caught, for example SIGKILL (9). If that is sent to a process, it will exit immediately and no further instructions from it will be executed (with one exception, if the process is currently inside a kernel syscall it usually can't be interrupted, so the process will exit as soon as the syscall finishes). This should normally not be used except in extreme circumstances
How a particular program behaves when a signal is sent to it should be described in the documentation.
For modern kde and gnome applications, the intended method of sending commands to programs from scripts is with dbus.
Anders
Thanks for the explanation! So there is no way to make what I want in a legal way if I'm not sure how all the programs in my list handle the signals, right? -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 21/03/10 11:56, arygroup@gmail.com wrote:
On 21/03/10 13:47, Anders Johansson wrote:
On Sun, 2010-03-21 at 13:18 +0200, arygroup@gmail.com wrote:
I didn't read the kill manual, but I have a doubt. Is killing a program the same, as I close it in a legal way?
Depends on the program.
"kill" is really one of the worst named programs anywhere. It should have been called something like "signal", because that is what it does - it sends a signal to a given process. The signal INT (2) is the one sent by a shell when you press ctrl-c for example.
Most signals can be "caught" by an application, and many programs will catch the INT signal and do a controlled exit. Usually the same happens with the TERM signal, which is the default one sent by the kill command if you don't specify something else.
The HUP signal is used by some applications to trigger a re-read of the configuration without having to restart. Postfix for example uses this
Some signals can't be caught, for example SIGKILL (9). If that is sent to a process, it will exit immediately and no further instructions from it will be executed (with one exception, if the process is currently inside a kernel syscall it usually can't be interrupted, so the process will exit as soon as the syscall finishes). This should normally not be used except in extreme circumstances
How a particular program behaves when a signal is sent to it should be described in the documentation.
For modern kde and gnome applications, the intended method of sending commands to programs from scripts is with dbus.
Anders
Thanks for the explanation!
So there is no way to make what I want in a legal way if I'm not sure how all the programs in my list handle the signals, right?
It's completely legal, just a question of whether the application author did their job well and considered the needs of command-line users. SIGTERM (the default signal from kill) is simply "asking" the program to quit, so a well-written program should have plenty of time to save config etc. and shutdown cleanly. So there should be no danger to sending SIGKILL or SIGHUP to a well-written program. In fact the normal logout/shutdown process involves sending SIGTERM to all processes. On the other hand SIGKILL (kill -9) is an immediate end to the program. But anyway pidgin you can cleanly quit using /usr/bin/purple-remote "quit" (purple-remote is a program specifically for remotely controlling pidgin and other libpurple-based programs via DBUS, it should be installed with pidgin) Thunderbird seems to shutdown cleanly on a SIGHUP on my machine. Skype and dropbox you'll need to experiment with. Regards, Tejas -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sunday March 21 2010, Tejas Guruswamy wrote:
On 21/03/10 11:56, arygroup@gmail.com wrote:
...
So there is no way to make what I want in a legal way if I'm not sure how all the programs in my list handle the signals, right?
It's completely legal, just a question of whether the application author did their job well and considered the needs of command-line users. SIGTERM (the default signal from kill) is simply "asking" the program to quit, so a well-written program should have plenty of time to save config etc. and shutdown cleanly. So there should be no danger to sending SIGKILL or SIGHUP to a well-written program.
Just to be clear, no process may catch SIGKILL, so any program that requires shut-down processing (say, to ensure the integrity of any files they use) may corrupt that external data if stopped using SIGKILL.
In fact the normal logout/shutdown process involves sending SIGTERM to all processes. On the other hand SIGKILL (kill -9) is an immediate end to the program.
...
Regards, Tejas
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 21/03/10 16:11, Randall R Schulz wrote:
On Sunday March 21 2010, Tejas Guruswamy wrote:
On 21/03/10 11:56, arygroup@gmail.com wrote:
...
So there is no way to make what I want in a legal way if I'm not sure how all the programs in my list handle the signals, right?
It's completely legal, just a question of whether the application author did their job well and considered the needs of command-line users. SIGTERM (the default signal from kill) is simply "asking" the program to quit, so a well-written program should have plenty of time to save config etc. and shutdown cleanly. So there should be no danger to sending SIGKILL or SIGHUP to a well-written program.
Just to be clear, no process may catch SIGKILL, so any program that requires shut-down processing (say, to ensure the integrity of any files they use) may corrupt that external data if stopped using SIGKILL.
That was a typo, I meant SIGTERM in that sentence, thanks for the catch, you are absolutely correct.
In fact the normal logout/shutdown process involves sending SIGTERM to all processes. On the other hand SIGKILL (kill -9) is an immediate end to the program.
And I did mean SIGKILL here ;)
Regards, Tejas -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (6)
-
Anders Johansson
-
arygroup@gmail.com
-
David Haller
-
Ed Greshko
-
Randall R Schulz
-
Tejas Guruswamy