Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a way to terminate a root process without entering an administrator's password?

You might be wondering why I'd want to do this 'cause it sounds fishy. Well I just need to end a process started by a daemon from an agent but daemons runs as root and agents are user specific.

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

Users are only allowed to kill or otherwise signal their own processes.

You say that the process is started by a daemon running as root. Does that process need to run as root as well? If it doesn't, make it drop privileges and run as the desired user.

If the process must run as root, you'll have to provide a way for the agent to elevate its privileges to kill the process. This can take the form of a setuid root helper executable, or an entry in the sudoers file (with the NOPASSWD tag). The sudo entry has the advantage that its use will be logged.

Note that there is no atomic way to send a signal to a process. Sending a signal is asynchronous: it is possible that you obtain the PID of a process, then you send a signal to that process, but the process has died in the meantime and its process ID has already been reused by another process.

There's a way to avoid this involving the parent of the process you want to kill, but it's complicated. The process ID will not disappear until its parent acknowledges the child's death (a zombie process remains until then). To use this effectively, you need the parent to know that it must hold on until no agent it going to want tot kill the child.

If you're not concerned with the race condition, you can give the agent the permission to run pkill name_of_process_to_kill, if you know that there will be a single process with that name. If you can identify the process by a file it has open, you can use fuser -k /path/to/file.

If you can, modify the process so that it listens to a termination request on a pipe or socket. Set up the permissions or authentication on the pipe or socket according to your needs.

share|improve this answer
    
The process is run as root just 'cause it is called by a damon; dropping its privileges would be the best solution. Any ideas on how this is done are greatly appreciated –  Samantha Catania Sep 23 '11 at 5:15
    
setuid() was the best solution –  Samantha Catania Sep 23 '11 at 7:29
    
Continued here. –  Gilles Sep 23 '11 at 7:34
add comment

You should look into sudo.

You can configure it to let you enter any command without a password, or just some like kill, or to ask for your user password (not root's, yours) on every command, etc. It is very flexible.

It may already be installed and set up on your system. This is the case on Ubuntu and OS X, for example. If not, it is available for most Unixy systems.

share|improve this answer
    
I used sudo but it still asks for the password; I have to implement this in a program so I can't have the user enter the password –  Samantha Catania Sep 22 '11 at 15:23
1  
@Samantha "You can configure it to let you enter any command without a password". See this question –  Michael Mrozek Sep 22 '11 at 15:45
    
I can't configure it that way –  Samantha Catania Sep 22 '11 at 17:00
    
@SamanthaCatania: why you can't? You are not able to, or you do not have privilege to modify /etc/sudoers? –  enzotib Sep 22 '11 at 17:03
    
As I wrote in the question this must be done from an agent program there must be no input from the user & there is no terminal window –  Samantha Catania Sep 22 '11 at 17:07
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.