Background processes
How to administer background processes.
View and stop
Use the following commands if you want to view or stop running processes.
ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
someuser 1170 0.0 0.0 151232 1992 ? Sl 2019 50:29 /usr/bin/redis-server 127.0.0.1:0
someuser 1172 0.0 0.0 151232 1988 ? Sl 2019 50:22 /usr/bin/redis-server 127.0.0.1:0
someuser 2000 0.0 0.0 1136972 10256 ? S 2019 0:00 php-fpm: pool php70-someuser-website.com
someuser 2004 0.0 0.0 1136972 10256 ? S 2019 0:00 php-fpm: pool php70-someuser-website.com
someuser 2010 0.0 0.0 1136972 10248 ? S 2019 0:00 php-fpm: pool php70-someuser-website.com
someuser 2013 0.0 0.0 1136972 10252 ? S 2019 0:00 php-fpm: pool php70-someuser-website.com
someuser 2017 0.0 0.0 1136972 10252 ? S 2019 0:00 php-fpm: pool php70-someuser-website.com
someuser 2021 0.0 0.0 1136972 10252 ? S 2019 0:00 php-fpm: pool php70-someuser-website.com
someuser 2030 0.0 0.0 1136972 10248 ? S 2019 0:00 php-fpm: pool php70-someuser-website.com
someuser 2033 0.0 0.0 1136972 10248 ? S 2019 0:00 php-fpm: pool php70-someuser-website.com
someuser 2038 0.0 0.0 1136972 10244 ? S 2019 0:00 php-fpm: pool php70-someuser-website.com
someuser 2039 0.0 0.0 1136972 10244 ? S 2019 0:00 php-fpm: pool php70-someuser-website.com
someuser 2043 0.0 0.0 1136972 10240 ? S 2019 0:00 php-fpm: pool php70-someuser-website.com
someuser 2049 0.0 0.0 1136972 10240 ? S 2019 0:00 php-fpm: pool php70-someuser-website.com
someuser 2052 0.0 0.0 1136972 10240 ? S 2019 0:00 php-fpm: pool php70-someuser-website.com
someuser 2057 0.0 0.0 1136972 10240 ? S 2019 0:00 php-fpm: pool php70-someuser-website.com
someuser 2063 0.0 0.0 1136972 10240 ? S 2019 0:00 php-fpm: pool php70-someuser-website.com
someuser 2066 0.0 0.0 1136972 10240 ? S 2019 0:00 php-fpm: pool php70-someuser-website.com
someuser 104977 0.0 0.0 780800 64508 ? Sl 03:00 0:00 /usr/bin/hhvm -m server -c /etc/hhvm.d/someuser-website.com.ini
someuser 128392 0.0 0.0 116588 3460 pts/0 Ss+ 19:09 0:00 -bash
someuser 131513 0.0 0.0 217640 12924 ? Ss Jan31 1:57 /usr/bin/python /usr/bin/supervisord -n -c /etc/supervisor/someuser.conf
someuser 131547 0.5 0.1 368324 160500 ? Sl Jan31 55:26 /usr/bin/redis-server 127.0.0.1:6385
someuser 131548 138 1.0 11902864 1443848 ? Sl Jan31 13629:09 /usr/bin/java -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -Djava.awt.headless=true -Dfile.encoding=UTF-8 -XX:
someuser 133746 0.0 0.0 116456 2960 pts/1 Ss+ 19:36 0:00 -bash
someuser 147910 3.0 0.0 116456 3192 pts/2 Ss 20:14 0:00 -bash
someuser 147959 0.0 0.0 151156 1828 pts/2 R+ 20:14 0:00 ps aux
A closer look tells us the process with pid 131548
is running for a long time and is showing high CPU usage.
This process may be stopped by using this command:
kill 131548
If a process is really stuck and no longer responds to a SIGTERM, you may also use SIGKILL. This forces the OS to stop the process. As a result the process will not be able to stop in a planned manner and some child processes or other remnants may still be present.
kill -9 131548
Read https://linuxhandbook.com/sigterm-vs-sigkill/ to learn more about the difference between SIGTERM and SIGKILL.
If you want to stop all processes of a certain type, you may use killall
.
To reset PHP use the following command:
killall php-fpm
screen
If you want to start a background process you can use the screen
command:
For example:
screen sleep 100
You can leave this screen by using the key combination CTRL+A, CTRL+D.
To return use screen -r
.