Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Greetings all,
Due to another issue that I'm having with firefox, specifically the flash plugin which keeps causing it to freeze, I'm forced rather frequently to stop firefox with "kill -9" and restart it. I decided to try to write a shell script to automate this.
At this point, I have this
Code:
ps -A | grep firefox-bin | cut -c -6
Which lists all running processes, selects only the lines for firefox, then cuts off everything except for the process numbers. The only problem that I'm having is that most of the time there are two firefox-bin processes, and I get two different numbers on two different lines. How can I run kill -9 on one of these at a time?
I'd like to be able to automate it such that I run just one command and it kills firefox, then restarts it for me.
Which lists all running processes, selects only the lines for firefox, then cuts off everything except for the process numbers. The only problem that I'm having is that most of the time there are two firefox-bin processes, and I get two different numbers on two different lines. How can I run kill -9 on one of these at a time?
Yes, slackware does have the killall command; however when firefox hangs/freezes as it does due to the flash plugin, I need to use
Code:
kill -9
in order to kill it, kill or killall alone cannot do it, I need "-9" or the force parameter to successfully do it.
I think based upon what the others have posted though, that I should be able to pull it off. I'm not at my computer now, but I'm going to look into the xargs command, and and see what I can do with that.
Also, I can't believe that I forgot about the "head" command, silly me. :-p
Thank you very much for the idea. The only problem with this, which comes not from your contribution, but from my original code, is that if I use cut with the -6 option, and the process is only 5 digits long, I get
Now if I change the code to "cut -c -5", it works fine. I would just change the code, but sometimes the process numbers do get up to six digits.
Should I set it up to try it with 6 first, then run the same string of commands again with -5? Or should I try to figure out how to make the script figure out how many digits the process number is, and then make the 5 or 6 arguments for cut be variables? Would this be possible? *head scratch*
I'm pretty sure it'd work if I just wrote it like this
But it's kind of brutish, and I really don't like to program in that style. I'd like to make something elegant that just works perfectly, but I'm not quite sure if it's possible.
It is kind of aggravating that when you run kill through xargs, that it recognizes the space as part of the process number. Oh! (I just got an idea while typing), is it possible to make xargs ignore that space? Or rather to ignore that space without affecting the way it reads the input from STDIN? I read the man page, and I know that you can change the way that it decides what counts as a separator, but I don't know if it would change the way it takes the input or executes kill.
/me starts reading more about bash scripting
Thanks everybody!
-Primux
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.