0

I'm trying to use Node.JS to provide a set of web services through restify. One of those services receives some params and then launches a process in background on Linux by using the method exec of child-process, passing as param to exec something like: "nohup program &". The process is launched without any problem, but it is killed after short interval even using nohup. I wonder if there is another way to launch a process in background through Node.JS. I've also tried to use the method spawn of child-process, but it seems that the process is not launched.

1

1 Answer 1

1

So both nohup and the & are not appropriate in this context. Those are utilities for when a human is using an interactive shell. When launching child processes programmatically as you are doing, you don't need them. Just launch your process by executable path/name directly. It will be in the "background" by default. The concept of "foreground" and "background" come from the notion of a single user with a single terminal screen, but remember that the OS normally runs many processes in parallel so calling something a "background" job is conceptually not quite right.

You also don't want nohup since again that is a special-purpose tool for allowing you to exit a parent shell process and leave a child process running, but in your case you want the default behavior that if your parent node.js process exits, the child worker processes should also exit.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.