1

I want to run pkill like below.

sudo pkill -u 11002

I cannot give sudo password multiple times, so I want to run pkill without sudo user. For this i copied pkill to home as named bkill, and then i have run the following command.

sudo setcap "cap_kill+epi" /home/rajesh/bkill

This will give kill capabilities to this binary. But whenever i run i am getting following message.

 /home/rajesh/bkill  -u 11002
result: 31270

I check running processes of that user using below command.

ps -u 11002

PID TTY          TIME CMD
340 pts/26   00:00:00 ncserver

This is showing process pid 340 is still running. I assumed cap_kill is not working.

So I tried a different approach. I have given sudo access using below commands.

sudo chown root /home/rajesh/bkill
sudo chmod u+s /home/rajesh/bkill

Even this way also not working.

Can anybody help me to resolve this??

Rajesh Barri
  • 121
  • 1
  • 4
  • The process in question may be trapping SIGTERM. Try SIGKILL (`pkill -KILL` or `pkill -9`). – muru Sep 04 '14 at 15:03
  • I tried those all signals. nothing is working. Anyhow thanks for your reply. – Rajesh Barri Sep 04 '14 at 17:43
  • It's possible that process is in [uninterruptible sleep](http://stackoverflow.com/a/223727/2072269), which is why signals aren't affecting it. – muru Sep 04 '14 at 18:05

1 Answers1

5

Why don't you just give yourself permission to run pkill without a password:

sudo visudo

add

rajesh ALL = NOPASSWD: /usr/bin/pkill

You'll still need to sudo pkill, but you won't have to type a password.

glenn jackman
  • 17,625
  • 2
  • 37
  • 60