Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Basically I want to dynamically start some processes which may create their own children processes, also I want to kill a certain group of processes I just created whenever I want.

One way I could think of is to start processes with a name (to distinguish as a group), then use pkill to kill them by the name.

The question is how to start a process with a name so that I can use pkill to kill them by the name? I am open to other solutions as well.

share|improve this question
    
Are you asking how to start a process with a name different from what it usually uses? Or are you just asking how to start a process from the command-line? –  Eliah Kagan Jun 21 '12 at 2:09
    
The process name is shown the same as its file name by default in Linux. I dont want to use its default file name as its process name nor change the file name every time I run. So I want to start the processes with a specific name that I want so that I can use 'pkill -f MyOwnName' to kill all the processes that I just started named MyOwnName at once . –  cache Jun 21 '12 at 2:13
add comment

1 Answer 1

You can use the exec shell builtin:

bash -c "exec -a MyUniqueProcessName <command> &"

<command> replaces the current shell, no new process is created, that's why I'm starting a new shell to call exec.

Then you can kill the process with:

pkill -f MyUniqueProcessName

You can start more than one process under the same name, then pkill -f <name> will kill all of them.

share|improve this answer
add 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.