Is there an easy way to check for an application's PID# & kill it using a script? -- ...CH SuSE 9 Works Linux user# 313696 Linux box# 199365
On Wed, 2 Jun 2004 02:29, C Hamel wrote:
Is there an easy way to check for an application's PID# & kill it using a script? -- ...CH SuSE 9 Works Linux user# 313696 Linux box# 199365
Have a look at the killall command man killall -- Regards, Graham Smith ---------------------------------------------------------
On Tuesday 01 June 2004 11:46, Graham Smith wrote:
On Wed, 2 Jun 2004 02:29, C Hamel wrote:
Is there an easy way to check for an application's PID# & kill it using a script? -- ...CH SuSE 9 Works Linux user# 313696 Linux box# 199365
Have a look at the killall command man killall -- Regards,
Graham Smith --------------------------------------------------------- Wow!! I'm really impressed with the number of people who find it difficult to see the work SCRIPT!! <LOL> -- ...CH SuSE 9 Works Linux user# 313696 Linux box# 199365
On Wed, 2 Jun 2004 04:18, C Hamel wrote:
On Tuesday 01 June 2004 11:46, Graham Smith wrote:
On Wed, 2 Jun 2004 02:29, C Hamel wrote:
Is there an easy way to check for an application's PID# & kill it using a script? -- ...CH SuSE 9 Works Linux user# 313696 Linux box# 199365
Have a look at the killall command man killall -- Regards,
Graham Smith ---------------------------------------------------------
Wow!! I'm really impressed with the number of people who find it difficult to see the work SCRIPT!! <LOL>
Yes I did see your message and did read it. You can easily use killall in a script, for examples refer to the init scripts in /etc/init.d As you didn't specify anything regarding the script, how can we really respond. There are 100 of ways of determining the PID of a running process and depending on the process running different methods may be required. Also a script can be written in python, perl, bash or any of 50 other script languages. If you want an example please ask and specify want language and what the purpose of the script is for. Otherwise don't complain if you don't get what you think you want. -- Regards, Graham Smith ---------------------------------------------------------
On Tuesday 01 June 2004 13:52, Graham Smith wrote:
On Wed, 2 Jun 2004 04:18, C Hamel wrote:
On Tuesday 01 June 2004 11:46, Graham Smith wrote:
On Wed, 2 Jun 2004 02:29, C Hamel wrote:
Is there an easy way to check for an application's PID# & kill it using a script? -- ...CH SuSE 9 Works Linux user# 313696 Linux box# 199365
Have a look at the killall command man killall -- Regards,
Graham Smith ---------------------------------------------------------
Wow!! I'm really impressed with the number of people who find it difficult to see the work SCRIPT!! <LOL>
Yes I did see your message and did read it. You can easily use killall in a script, for examples refer to the init scripts in /etc/init.d
As you didn't specify anything regarding the script, how can we really respond. There are 100 of ways of determining the PID of a running process and depending on the process running different methods may be required. Also a script can be written in python, perl, bash or any of 50 other script languages. If you want an example please ask and specify want language and what the purpose of the script is for. Otherwise don't complain if you don't get what you think you want.
-- Regards,
Graham Smith --------------------------------------------------------- <LMAO> SO you finally figured out that I'm not script-savvy!! <G> I admit it!! No wonder I couldn't ask an intelligent question, huh? :-\ <LOL> -- ...CH SuSE 9 Works Linux user# 313696 Linux box# 199365
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 01 June 2004 14:17, C Hamel wrote:
<LMAO> SO you finally figured out that I'm not script-savvy!! <G> I admit it!! No wonder I couldn't ask an intelligent question, huh? :-\ <LOL>
You tried, and the philosophy here is that the only dumb question is the one that doesn't get asked. Actually, you got more than one way of doing it in a script - even *BEFORE* you reminded us that it was in a script. There were several references to the killall command. This command uses the name of an application instead of the pid. For example: if program 'abc' is running and you want to kill it (either at a command line or in a script), the command killall abc would terminate all instances of that program without referencing the pid directly. To get some more information on the "killall" command, open a console and enter the command man killall and read the manual pages on it -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQFAvOJZjeziQOokQnARAvBaAKCBVsYjSnTub0rqDecLe/zyLDrAwQCgjx5F IcWNLRQzEcSErc7c7h+5huw= =hHKe -----END PGP SIGNATURE-----
On Tuesday 01 June 2004 15:08, Michael Satterwhite wrote:
On Tuesday 01 June 2004 14:17, C Hamel wrote:
<LMAO> SO you finally figured out that I'm not script-savvy!! <G> I admit it!! No wonder I couldn't ask an intelligent question, huh? :-\ <LOL>
You tried, and the philosophy here is that the only dumb question is the one that doesn't get asked. Actually, you got more than one way of doing it in a script - even *BEFORE* you reminded us that it was in a script.
There were several references to the killall command. This command uses the name of an application instead of the pid. For example: if program 'abc' is running and you want to kill it (either at a command line or in a script), the command
killall abc
would terminate all instances of that program without referencing the pid directly. To get some more information on the "killall" command, open a console and enter the command
man killall
and read the manual pages on it
That's *just* what I need! I was playing with the kill command & forgot all about the killall. I think that is just what I need to add to my existing script so that I can restart mldonkey if/when a reconnection to the net takes place. I find that it behaves far better if restarted, too. Thanks! -- ...CH SuSE 9 Works Linux user# 313696 Linux box# 199365
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 01 June 2004 5:20 pm, C Hamel wrote:
That's *just* what I need! I was playing with the kill command & forgot all about the killall. I think that is just what I need to add to my existing script so that I can restart mldonkey if/when a reconnection to the net takes place. I find that it behaves far better if restarted, too.
You should shut it down cleanly: echo -e "kill\nq\n" | netcat 127.0.0.1 4000 - -- James Oakley Engineering - SolutionInc Ltd. joakley@solutioninc.com http://www.solutioninc.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFAvc254U2uQswGyDcRAgugAJ9OYgbcGfB9PtTTo/VWxKUuSnswbwCgxdRi RbZhzEjZG2g/SElYgWg2VPc= =fQr+ -----END PGP SIGNATURE-----
* C Hamel
On Tuesday 01 June 2004 11:46, Graham Smith wrote:
On Wed, 2 Jun 2004 02:29, C Hamel wrote:
Is there an easy way to check for an application's PID# & kill it using a script? -- ...CH SuSE 9 Works Linux user# 313696 Linux box# 199365
Have a look at the killall command man killall -- Regards,
Graham Smith --------------------------------------------------------- Wow!! I'm really impressed with the number of people who find it difficult to see the work SCRIPT!! <LOL> -- ...CH SuSE 9 Works Linux user# 313696 Linux box# 199365
They probably missed it trying to sort thru the sig's, etc. from the full quoting :^(. -- Patrick Shanahan Registered Linux User #207535 http://wahoo.no-ip.org @ http://counter.li.org HOG # US1244711
C Hamel wrote:
On Tuesday 01 June 2004 11:46, Graham Smith wrote:
On Wed, 2 Jun 2004 02:29, C Hamel wrote:
Is there an easy way to check for an application's PID# & kill it using a script? -- ...CH SuSE 9 Works Linux user# 313696 Linux box# 199365
Have a look at the killall command man killall -- Regards,
Graham Smith ---------------------------------------------------------
Wow!! I'm really impressed with the number of people who find it difficult to see the work SCRIPT!! <LOL>
I saw the word "script", but the way you composed the original message, made it appear you didn't know about killall, which will do precisely what you're trying to accomplish.
On Tuesday 01 June 2004 20.18, C Hamel wrote:
Wow!! I'm really impressed with the number of people who find it difficult to see the work SCRIPT!! <LOL>
and I'm impressed by the number of people who haven't a clue what a script is. A script is a sequence of one or more shell commands. ls is a script killall is a script if you want to put your script in a file, you should put #!<command> on the first line, where <command> is the program you want to execute your sequence of commands. That's it. That's what a script is.
Thanks to everyone who offered ideas or otherwise pulled my chain. :-) I think I'm getting a handle on it. -- ...CH SuSE 9 Works Linux user# 313696 Linux box# 199365
Anders Johansson wrote:
On Tuesday 01 June 2004 20.18, C Hamel wrote:
Wow!! I'm really impressed with the number of people who find it difficult to see the work SCRIPT!! <LOL>
and I'm impressed by the number of people who haven't a clue what a script is.
OK, are you sitting down- you are about to be impressed again :-). I didn't know that. I always assumed that a script was akin to a batch file (as in Windows).
A script is a sequence of one or more shell commands.
ls
is a script
killall
is a script
if you want to put your script in a file, you should put #!<command> on the first line, where <command> is the program you want to execute your sequence of commands. That's it. That's what a script is.
When I read the above you could have blown me over with a feather. Live and learn. Could this then be the reason why what is suggested in Suse's Support Database about getting the time synced with a time server is not working for me. The SD states that to sync time one issues the command ntpdate <URL of time server> followed by hwclock -w and Voila! your system clock will be in perfect sync with the atomic (or neutron or whatever) clock of the server of your choice. What I have been doing, as root, is to issue this command after I have made a connection to the 'Net: ntpdate 203.21.37.18 && hwclock -w and the clock gets synced. The SD further states that one can automate this by creating a file called ip-up.local in /etc/ppp/ and placing these commands in it and the time will be synced on each connect to the 'Net. So I did as suggested - but this doesn't appear to be working because my time can get anything up to 90 seconds out after the connection and me executing the commands manually a few seconds after the connect. From your comments about the '#!<command>', do I need to rewrite the ip-up.local file to begin with #!ntpdate 203.21.37.18 #!hwclock -w ? (I'd try doing this right now but I am too worried about having smoke come out of the box- this system has been up and running too well since I installed v9.0 when it was released :-).) Cheers. -- I am not young enough to know everything.
On Wednesday 02 June 2004 08.01, Basil Chupin wrote:
Anders Johansson wrote:
On Tuesday 01 June 2004 20.18, C Hamel wrote:
Wow!! I'm really impressed with the number of people who find it difficult to see the work SCRIPT!! <LOL>
and I'm impressed by the number of people who haven't a clue what a script is.
OK, are you sitting down- you are about to be impressed again :-).
I didn't know that.
I always assumed that a script was akin to a batch file (as in Windows).
I don't know. Are there things you can do in a batch file that you can't do from a plain dos prompt? Because there's nothing you can do in a bash script that you can't do from a bash command line. I guess they're somewhat equivalent, although if you just say "script" then the terms are very different. The generic term "script" could just as easily be applied to other programs, not just shells
A script is a sequence of one or more shell commands.
my mistake here. Sorry 'bout that. That should have read "A _shell_ script is..."
ls
is a script
killall
is a script
if you want to put your script in a file, you should put #!<command> on the first line, where <command> is the program you want to execute your sequence of commands. That's it. That's what a script is.
When I read the above you could have blown me over with a feather. Live and learn.
Could this then be the reason why what is suggested in Suse's Support Database about getting the time synced with a time server is not working for me.
The SD states that to sync time one issues the command
ntpdate <URL of time server>
followed by
hwclock -w
and Voila! your system clock will be in perfect sync with the atomic (or neutron or whatever) clock of the server of your choice.
What I have been doing, as root, is to issue this command after I have made a connection to the 'Net:
ntpdate 203.21.37.18 && hwclock -w
and the clock gets synced.
The SD further states that one can automate this by creating a file called ip-up.local in /etc/ppp/ and placing these commands in it and the time will be synced on each connect to the 'Net.
So I did as suggested - but this doesn't appear to be working because my time can get anything up to 90 seconds out after the connection and me executing the commands manually a few seconds after the connect.
From your comments about the '#!<command>', do I need to rewrite the ip-up.local file to begin with
#!ntpdate 203.21.37.18 #!hwclock -w
No no, the <command> there is /bin/bash, since that is what you're using to run your commands. The fact that your commands also happen to be external programs is less important. In a python script, the <command> would be /usr/bin/python, in a perl script the <command> would be /usr/bin/perl and so on. A script file can only have one hash-bang (the term used for #!), and it needs to be the first line in the script, and the program referenced in the hash-bang is the program that is run by the system. Anything else in that file is then the responsibility of that program to interpret and execute So in your case ip-up.local should look like <quote> #!/bin/bash ntpdate 203.21.37.18 && hwclock -w </quote> since /etc/ppp/ip-up executes it instead of "sourcing" it. If the line in /etc/ppp/ip-up had been ". /etc/ppp/ip-up.local" (dot space) then you wouldn't have needed the hash-bang, since then bash would have read the file as part of the current script
Anders Johansson wrote:
On Wednesday 02 June 2004 08.01, Basil Chupin wrote:
Anders Johansson wrote:
On Tuesday 01 June 2004 20.18, C Hamel wrote:
Wow!! I'm really impressed with the number of people who find it difficult to see the work SCRIPT!! <LOL>
and I'm impressed by the number of people who haven't a clue what a script is.
OK, are you sitting down- you are about to be impressed again :-).
I didn't know that.
I always assumed that a script was akin to a batch file (as in Windows).
I don't know. Are there things you can do in a batch file that you can't do from a plain dos prompt? Because there's nothing you can do in a bash script that you can't do from a bash command line. I guess they're somewhat equivalent, although if you just say "script" then the terms are very different. The generic term "script" could just as easily be applied to other programs, not just shells
A script is a sequence of one or more shell commands.
my mistake here. Sorry 'bout that. That should have read "A _shell_ script is..."
ls
is a script
killall
is a script
if you want to put your script in a file, you should put #!<command> on the first line, where <command> is the program you want to execute your sequence of commands. That's it. That's what a script is.
When I read the above you could have blown me over with a feather. Live and learn.
Could this then be the reason why what is suggested in Suse's Support Database about getting the time synced with a time server is not working for me.
The SD states that to sync time one issues the command
ntpdate <URL of time server>
followed by
hwclock -w
and Voila! your system clock will be in perfect sync with the atomic (or neutron or whatever) clock of the server of your choice.
What I have been doing, as root, is to issue this command after I have made a connection to the 'Net:
ntpdate 203.21.37.18 && hwclock -w
and the clock gets synced.
The SD further states that one can automate this by creating a file called ip-up.local in /etc/ppp/ and placing these commands in it and the time will be synced on each connect to the 'Net.
So I did as suggested - but this doesn't appear to be working because my time can get anything up to 90 seconds out after the connection and me executing the commands manually a few seconds after the connect.
From your comments about the '#!<command>', do I need to rewrite the ip-up.local file to begin with
#!ntpdate 203.21.37.18 #!hwclock -w
No no, the <command> there is /bin/bash, since that is what you're using to run your commands. The fact that your commands also happen to be external programs is less important.
In a python script, the <command> would be /usr/bin/python, in a perl script the <command> would be /usr/bin/perl and so on.
A script file can only have one hash-bang (the term used for #!), and it needs to be the first line in the script, and the program referenced in the hash-bang is the program that is run by the system. Anything else in that file is then the responsibility of that program to interpret and execute
So in your case ip-up.local should look like
<quote> #!/bin/bash
ntpdate 203.21.37.18 && hwclock -w </quote>
since /etc/ppp/ip-up executes it instead of "sourcing" it. If the line in /etc/ppp/ip-up had been ". /etc/ppp/ip-up.local" (dot space) then you wouldn't have needed the hash-bang, since then bash would have read the file as part of the current script
Thank you for the explanation. I've looked inside a similar file in /etc/ppp/ and found that it begins with #!/bin/sh and not .../bash so I used sh in my new ip-up.local file. I'll see what happens at the next logon. And while I don't fully understand the whole thing, I can see a glimmer of a light in what you said in the last paragraph about /etc/ppp/ip-up and how it picks-up ip-up.local. Cheers. -- I am not young enough to know everything.
On Wed, Jun 02, 2004 at 09:42:39PM +1000, Basil Chupin Wrote:
Thank you for the explanation.
I've looked inside a similar file in /etc/ppp/ and found that it begins with #!/bin/sh and not .../bash so I used sh in my new ip-up.local file. I'll see what happens at the next logon.
And while I don't fully understand the whole thing, I can see a glimmer of a light in what you said in the last paragraph about /etc/ppp/ip-up and how it picks-up ip-up.local.
Cheers.
#!/bin/sh is a sym link to /bin/bash, i.e., /bin/sh is /bin/bash :) -- .~. /V\ Robert Sweet // \\ Systems Administration and Installation /( )\ www.garagenetworks.net ^^-^^ 714.596.5504
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday 03 June 2004 3:40 am, Robert Sweet wrote:
#!/bin/sh is a sym link to /bin/bash, i.e., /bin/sh is /bin/bash :)
Watch out. Bash's behaviour changes depending on how you call it. I found out the hard way while debugging a script that used Bash 2 features and had #!/bin/bash at the top. I was using "sh -x <scriptname>" to debug it... - -- James Oakley Engineering - SolutionInc Ltd. joakley@solutioninc.com http://www.solutioninc.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFAvxv74U2uQswGyDcRAo7jAKCRb1Uo5QC3nR+B9QPrR5H//GVZKwCfZvCk VHv/LYl5tkbuFoCCOhDTScM= =b6c/ -----END PGP SIGNATURE-----
On Thursday 03 June 2004 07:39, James Oakley wrote:
On Thursday 03 June 2004 3:40 am, Robert Sweet wrote:
#!/bin/sh is a sym link to /bin/bash, i.e., /bin/sh is /bin/bash :)
Watch out. Bash's behaviour changes depending on how you call it.
I found out the hard way while debugging a script that used Bash 2 features and had #!/bin/bash at the top. I was using "sh -x <scriptname>" to debug it...
-- James Oakley Engineering - SolutionInc Ltd. joakley@solutioninc.com http://www.solutioninc.com Gave it a dry run. Seems to work okay. -- ...CH SuSE 9 Works Linux user# 313696 Linux box# 199365
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday 01 June 2004 11:29, C Hamel wrote:
Is there an easy way to check for an application's PID# & kill it using a script?
May not be what you're looking for, but you might try killall <appname> where appname is the app you're trying to kill. You don't need the PID for that. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQFAvLPqjeziQOokQnARAtyVAJsEoPl8ciK6RIf9C4bl5SaaGMPPiQCeM+eX pgtSKbL/PdDj1gX2kfONVTo= =1lAV -----END PGP SIGNATURE-----
* C Hamel
Is there an easy way to check for an application's PID# & kill it using a script?
You might want to use killall, but here's how to do it without: $ for i in `pidof application`; do kill $i; done -- Mads Martin Joergensen, http://mmj.dk "Why make things difficult, when it is possible to make them cryptic and totally illogical, with just a little bit more effort?" -- A. P. J.
On Tuesday 01 June 2004 13:24, Mads Martin Joergensen wrote:
* C Hamel
[Jun 01. 2004 18:33]: Is there an easy way to check for an application's PID# & kill it using a script?
You might want to use killall, but here's how to do it without:
$ for i in `pidof application`; do kill $i; done
-- Mads Martin Joergensen, http://mmj.dk "Why make things difficult, when it is possible to make them cryptic and totally illogical, with just a little bit more effort?" -- A. P. J. THANK YOU!! <G> That's what I couldn't seem to make happen, I think! -- ...CH SuSE 9 Works Linux user# 313696 Linux box# 199365
On 01.06.04,11:29, C Hamel wrote:
Is there an easy way to check for an application's PID# & kill it using a script? --
I like this way:
#!/bin/sh
while true
do
kill -9 `ps aux | grep -i $1 | awk '{ print $2 }'` sleep 2
done
put this in a script called kl. And run for ex. 'kl mozilla' when it
gets to heavy.
- Jostein
--
Jostein Berntsen
On 01.06.04,11:29, C Hamel wrote:
Is there an easy way to check for an application's PID# & kill it using a script? --
I like this way:
#!/bin/sh while true do kill -9 `ps aux | grep -i $1 | awk '{ print $2 }'` sleep 2 done
put this in a script called kl. And run for ex. 'kl mozilla' when it gets to heavy.
- Jostein
-- Jostein Berntsen
I like the simplicity, but is the usual test for a pid done beforehand for the
On Wednesday 02 June 2004 08:07, Jostein Berntsen wrote: particular application? -- ...CH SuSE 9 Works Linux user# 313696 Linux box# 199365
* C Hamel
On Wednesday 02 June 2004 08:07, Jostein Berntsen wrote:
I like this way:
#!/bin/sh while true do kill -9 `ps aux | grep -i $1 | awk '{ print $2 }'` sleep 2 done
put this in a script called kl. And run for ex. 'kl mozilla' when it gets to heavy.
I like the simplicity, but is the usual test for a pid done beforehand for the particular application?
Find a site on the web which describes bash scripts such as: http://www.tldp.org/LDP/abs/html/ and decipher the script as you would parse a sentense in english and you will *learn* for yourself what you have asked. And you will be more likely to remember the method and become self-sufficient. Then the next time you have a similar question, you will be able to search for the answer yourself instead of *depending* on others efforts to supplement your knowledge when the information is *so* readily available. I would be more than happy to mow my neighbor's grass when he is out of town or temporarily physically unable, but not while he is able and lounging on the patio drinking a cold Budweiser. -- Patrick Shanahan Registered Linux User #207535 http://wahoo.no-ip.org @ http://counter.li.org HOG # US1244711
On Wednesday 02 June 2004 10:38, Patrick Shanahan wrote:
* C Hamel
[06-02-04 10:10]: On Wednesday 02 June 2004 08:07, Jostein Berntsen wrote:
I like this way:
#!/bin/sh while true do kill -9 `ps aux | grep -i $1 | awk '{ print $2 }'` sleep 2 done
put this in a script called kl. And run for ex. 'kl mozilla' when it gets to heavy.
I like the simplicity, but is the usual test for a pid done beforehand for the particular application?
Find a site on the web which describes bash scripts such as: http://www.tldp.org/LDP/abs/html/ and decipher the script as you would parse a sentense in english and you will *learn* for yourself what you have asked. And you will be more likely to remember the method and become self-sufficient.
Then the next time you have a similar question, you will be able to search for the answer yourself instead of *depending* on others efforts to supplement your knowledge when the information is *so* readily available.
I would be more than happy to mow my neighbor's grass when he is out of town or temporarily physically unable, but not while he is able and lounging on the patio drinking a cold Budweiser. -- Patrick Shanahan Registered Linux User #207535 http://wahoo.no-ip.org @ http://counter.li.org HOG # US1244711 Point taken... and that is *exactly* what I am doing! :-) Someone else was kind enough to deliver some resource links *w/o* bitching me out! <G>
Regards... -- ...CH SuSE 9 Works Linux user# 313696 Linux box# 199365
* C Hamel
On Wednesday 02 June 2004 10:38, Patrick Shanahan wrote:
Find a site on the web which describes bash scripts such as: http://www.tldp.org/LDP/abs/html/ and decipher the script as you would parse a sentense in english and you will *learn* for yourself what you have asked. And you will be more likely to remember the method and become self-sufficient.
Then the next time you have a similar question, you will be able to search for the answer yourself instead of *depending* on others efforts to supplement your knowledge when the information is *so* readily available.
I would be more than happy to mow my neighbor's grass when he is out of town or temporarily physically unable, but not while he is able and lounging on the patio drinking a cold Budweiser.
Point taken... and that is *exactly* what I am doing! :-) Someone else was kind enough to deliver some resource links *w/o* bitching me out! <G>
No *bitching*. A suggested avenue that would benefit your knowledge base. Generally, an effort should be made to answer your own questions before asking the list. You will learn more unless the effort is beyond you or not worth your time. I rec'd your direct/private post and responded similarily. gud luk, -- Patrick Shanahan Registered Linux User #207535 http://wahoo.no-ip.org @ http://counter.li.org HOG # US1244711
participants (11)
-
Anders Johansson
-
Basil Chupin
-
C Hamel
-
Graham Smith
-
James Knott
-
James Oakley
-
Jostein Berntsen
-
Mads Martin Joergensen
-
Michael Satterwhite
-
Patrick Shanahan
-
Robert Sweet