Start process with custom name via command line

Asked

Viewed 47 times

1

There is a process in my application that today whenever it runs keeps the name of the function as the name of the process in background.

However to perform some mapping, I wanted to customize the name of the process in the background.

Based on some examples of the Internet, I came up with the following model, however it is not working as it should.

I used a notation that is: bash -c "exec -a <NomeDoProcesso> <Comando>"

In my case, my script at the moment is that way:

bash -c "exec -a <NomeDoProcesso> nohup php index.php <Controller> <NomeDaFunção> > /var/www/log/ArquivoLog.log 2>&1 &"

However he still keeps on pulling the Function Name as the name of the process that is in the background, and not the Case name that I defined.

There is something wrong with my script or it is not really possible to move up the process with a custom name?

1 answer

1


One solution is to create a symlink with the name you want pointing to the program that will be run. Example:

foo

echo "$0 args $@"

bar

ln -s "foo" "novo-nome"
bash "novo-nome" "$@"

Testing:

chmod +x foo bar

./foo foo1 foo2
foo args foo1 foo2

./bar bar1 bar2
novo-nome args bar1 bar2

But in your case I think you could create a script and call it straight, ex:

new name.sh

php index.php <Controller> <NomeDaFunção> > /var/www/log/ArquivoLog.log

test

chmod +x novo-nome.sh
nohup novo-nome.sh
  • So I understand your suggestion and thank you for your contribution. But for example in my case, I would need the process name to be dynamic based on a variable of mine, even why within a PHP function I give the exec() to perform in bash. I don’t know if I’ve made that very clear in the question, that itself is my difficulty.

  • In that case, how would you need to call exec() in php even to define the name of the process, it would not fit me to use a file .sh for that reason.

  • Vc was unclear. The post is marked as bash and Ubuntu, not php. And for what is written in your publication you are using the shell to call the execution of a php script.

  • You are correct. I will give as answered because I tested your solution proposal and meets what I presented in the question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.