I am trying to kill a list of processes. I have found these two ways to list a group of process id's on a single line. How would I go about killing all of these processes all on one line?
As a "rule of thumb" anything that grep can do, awk can also achieve. So if you use awk, you most likely do not have to bother with another filter like grep.
There's also a very useful unix utility named `lsof' that can be handy when dealing with processes. If your system has it installed it is worthwhile to get familiar with it.
If you want to kill only the processes number of the program top that user 6243 has initiated.
kill $(lsof -t -u 6243 -a -c top)
-t: will output only the pid
-u: user id or name
-a: ANDing operator
-c: command
Can you please explain this part? I don't understand the purpose of a "~" here and why you had to the a.out in "//" . Would bash try to expand the "." if you didn't "\" it?
~ /a\.out/
The system I am using is old and unfortunately doesn't have lsof.
awk '$4 ~ /a\.out/ It is a matching pattern evaluation.
Let /pattern/ where pattern is a regular expression, therefore a `.' would match any character except the newline, thus the escape `\' to make it match just a single period character.
or - \. escapes the metacharacter . turning it into a regular character without special meaning. In regex there are several metacharacters a few are: ?.^$*+