Skip to content

Instantly share code, notes, and snippets.

@harshithjv
Last active February 18, 2024 10:20
Show Gist options
  • Save harshithjv/9c6499e36094d07ccf9e31d0af53ddfb to your computer and use it in GitHub Desktop.
Save harshithjv/9c6499e36094d07ccf9e31d0af53ddfb to your computer and use it in GitHub Desktop.
Killing all celery processes in one line.
# Killing all celery processes involves 'grep'ing on 'ps' command and run kill command on all PID. Greping
# on ps command results in showing up self process info of grep command. In order to skip that PID, 'grep
# -v grep' command is piplined which executes 'not' condition on 'grep' search key. The 'awk' command is
# used to filter only 2nd and 'tr' command translates result of 'awk' command output from rows to columns.
# Piplining 'kill' command did not work and so the entire process has been set as command substitution, i.e.,
# '$()'. The redirection at the end is not mandatory. Its only to supress the enitre output into background.
kill -9 $(ps aux | grep celery | grep -v grep | awk '{print $2}' | tr '\n' ' ') > /dev/null 2>&1
@sarkar7874
Copy link

Verify Github on Galaxy. gid:iGj7FA8dCWPUxUvXuX3RjY

@equilibrium-liberalism
Copy link

ps aux|grep celery
kill -9 $(ps aux | grep celery | grep -v grep | awk '{print $2}' | tr '\n' ' ') > /dev/null 2>&1

@quvonchbek-dev
Copy link

pkill -9 -f celery

))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment