ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I am practicing bash script.
I couldn't do this my book question.
How to do this?
Write a bash script that kills all the processes executing a certain command at a certain moment in time. For example, kill all processes running mail. Unless you have a super user privilege, you can kill only your own processes.
You just need to think about what you need to do and write the code:
+ Somehow get a list of the processes you want (is there a command that does this?).
+ kill each of those processes.
FYI, there are actually commands on several GNU/Linux distributions that already do this. Your prof just wants to see you learning your lessons. This should be pretty simple for you. Try it, you might learn something!
Hi ,
I am having problem running this script.
can u fix it to correct format pls?
write a bash script that kills all the processes executing a certain command at a certain moment in time. For example, kill all processes running mail. Unless you have a super user privilege, you can kill only your own processes.
Please stop asking homework questions. If you have an
approach to a solution feel free to come back and ask
for an explanation as to what you're doing wrong.
I've merged your two identical homework posts. Do not repost identicial questions in separate threads in an attempt to get someone to do your homework for you.
Originally posted by moodupani Hi ,
I am having problem running this script.
can u fix it to correct format pls?
write a bash script that kills all the processes executing a certain command at a certain moment in time. For example, kill all processes running mail. Unless you have a super user privilege, you can kill only your own processes.
#!/bin/sh
kill `ps -ef | grep $1 | awk '{ print $2 }'`
Hint: if you're having trouble figuring out what your script is (or isn't!) doing, split it into temporary files which you can examine at your leisure to see what each part of the pipeline is doing.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.