I have put a command in a bash script to kill processes as below
#!/bin/bash
kill -9 $(ps ux | grep 'fluent' | awk '{print $2}')
As I run the script, e.g. ./mykill, it has no effect
$ ps ux | grep fluent
ko 21690 0.0 0.0 112664 972 pts/3 S+ 15:28 0:00 grep --color=auto fluent
ko 26573 5.1 1.0 1743688 673592 ? Sl May14 836:08 /state/partition1/ans190/v190/fluent/cortex.19.0.0 -f fluent -cmd-port:35881:compute-0-4.local -workbench-session (fluent "3ddp -pshmem -host -alnamd64 -r19.0.0 -t16 -mpi=ibmmpi -path/state/partition1/ansys190/v190/fluent -ssh")
ko 26581 0.0 0.0 0 0 ? Z May14 0:00 [fluent] <defunct>
$
$
$ ~/mykill
Killed
$ ps ux | grep fluent
ko 21690 0.0 0.0 112664 972 pts/3 S+ 15:28 0:00 grep --color=auto fluent
ko 26573 5.1 1.0 1743688 673592 ? Sl May14 836:08 /state/partition1/ans190/v190/fluent/cortex.19.0.0 -f fluent -cmd-port:35881:compute-0-4.local -workbench-session (fluent "3ddp -pshmem -host -alnamd64 -r19.0.0 -t16 -mpi=ibmmpi -path/state/partition1/ansys190/v190/fluent -ssh")
ko 26581 0.0 0.0 0 0 ? Z May14 0:00 [fluent] <defunct>
However, if I run the command in the terminal, it will kill them.
$ kill -9 $(ps ux | grep 'fluent' | awk '{print $2}')
-bash: kill: (21899) - No such process
$ ps ux | grep fluent
ko 21915 0.0 0.0 112664 972 pts/3 S+ 15:31 0:00 grep --color=auto fluent
What is the reason then?