How to programatically stop background process?


Does anyone know how to how to programatically stop a background process?


If it’s a proper daemon of some kind, stop it using the appropriate commands or simply kill it.

If you kill the process, the following resource is helful:

You’ll want to use any of the options aside from bringing it to the foreground if you’re doing this in CircleCI since you won’t necessarily be there to pass ctrl-C.


Thanks for the response.
I should have been more clear that I want to know the answer within the context of circleci build environment and especially the circle.yml config. (I already know how to stop bg processes on a standard *nix environment.)

Let me be more clear about the setup.

Here’s the other details:

I have 3 sets of tests to run.
1st set of tests needs background processes running with command line args A.

2nd set of tests should run the background processes with different command line args B.

The 3rd set of tests should not have those background processes running at all.

I currently start the background processes in the test > pre section and only run the 1st set of tests in the test > override.
This works.
Now, I need to add the other 2 sets of tests.

What’s the best way to achieve this setup using a circle.yml configuration file?

Will it cause problems with Circle to repeatedly start and stop the processes in tests > override?



fyi, in my case, it completely didn’t matter whether background services were started in test > pre vs test > override.


What did matter was using SIGQUIT instead of default SIGTERM for my particular processes, especially celery. Otherwise, they would not shutdown fast enough to be ready for next round of tests.

Also, pkill on Circleci’s Ubuntu 12 has a different syntax than pkill on my dev box, Ubuntu 14.

And adding sleep, can give the background processes more time to start before tests hit them.

Example from test > override

- gunicorn myapp.wsgi --workers 1:
    background: true
- celery worker --app=myapp  --concurrency=1:
    background: true
- sleep 2
< run tests  here with concurrency of 1>
- pkill -SIGQUIT gunicorn
- pkill -SIGQUIT celery

- gunicorn myapp.wsgi --workers 2:
    background: true
- celery worker --app=myapp  --concurrency=2:
    background: true
- sleep 2
< run tests  here with concurrency of 2>
- pkill -SIGQUIT gunicorn
- pkill -SIGQUIT celery