1

I have a few processes that spring up and I am able to print a line of the pgid's that I would like to enter into a kill command.

here is what I have: sudo ps o pgid,args | grep mininet: | sudo awk '{print -$0}'

returns something like

-3834
-3841
-3844
-3846
-3848
-3853
-3856
-3859
-3862

I negated the output in the {print -$0} part so that they kill the children processes too.

the grep command searches for an argument in bash commands that denote the parent programs

now I would like to call sudo kill -SIGSTOP but I see here http://www.chemie.fu-berlin.de/chemnet/use/info/gawk/gawk_9.html that you can't use commands inside the awk other than conditionals, print,etc.. Am I mistaken on this or is there a way to redirect the input to the kill command to stop the processes.

context: pausing the mininet network emulator. I'd like to do this as a one-liner because it would be cool. Im sort of confused on how priority is given with | and how to input one command into the other.

Coding by the unix philosophy I shouldnt worry about bottlenecks until later but if someone thinks that this is a bad way to do this I would appreciate that info too.

Thanks~

edit:

This command stops the processes:

sudo ps o pgid,args | grep mininet: | sudo awk  '{system("sudo kill --signal SIGSTOP -"$1)}' - 

In awk you can use system("program ")

taking the advice this works to:

sudo pgrep -f mininet: | sudo awk  '{system("sudo kill --signal SIGCONT -"$1)}' - 
3
  • 1
    Try to use pgrep / pkill
    – Costas
    Jun 30, 2015 at 20:07
  • awk is a full programming language, so you can do many things within it that many people do not realize. However, for your case, you should almost certainly be looking into pgrep and pkill instead of going this route.
    – HalosGhost
    Jun 30, 2015 at 20:41
  • Okay I believe the pkill -f flag works to search the arguments but this does not stop the child processes
    – channon
    Jun 30, 2015 at 20:54

1 Answer 1

1

This command stops the processes:

sudo ps o pgid,args | grep mininet: | sudo awk  '{system("sudo kill --signal SIGSTOP -"$1)}' - 

In awk you can use system("program ")

taking the advice to use pgrep this works too:

sudo pgrep -f mininet: | sudo awk  '{system("sudo kill --signal SIGCONT -"$1)}' - 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .