PerkinElmer Informatics Support Forum
Decrease font size
Increase font size
Topic Title: How to automatically clean up stale python processes
Topic Summary:
Created On: 1/30/2019 11:55 AM
Status Post and Reply
Linear : Threading : Single : Branch
Topic Tools Topic Tools
View topic in raw text format. Print this topic.
 1/30/2019 11:55 AM
User is offline View Users Profile Print this message


Posts: 58
Joined: 5/13/2014

Under certain circumstances we observe that the number of python processes ( serving the Columbus webapp will accumulate. Most of these processes end up in an unused state (only the 6 most recent processes should remain active) and can ultimately have a negative impact on the Columbus application.

The following command will provide a count of the processes on the Columbus server.

$ ps -fU columbus | grep [m] | wc -l

If the output is greater than 10, the unused processes can be safely killed using the following command:

$ kill `ps kstart_time -fU columbus | awk '$3 != 1 && /[m] {print $2}' | head -n -10`

This command lists the PID of all but the 10 most recently spawned processes owned by the columbus user, then passes those PIDs to the kill command for removal.

As it is safe to remove these processes whilst the Columbus application is running, the cleanup can be automated using cron. Create a file named 'columbus_python_cleanup' within the /etc/cron.daily directory on the Columbus server and give the file the following content:


#!/bin/bash -e

## script to clean up stale python processes

cmd="ps kstart_time -fU columbus | awk '\$3 != 1 && /[m] {print \$2}' | head -n -$proc_limit"

orphans=$(eval $cmd)

if [[ ! -z "$orphans" ]]
kill $orphans


Now make the script executable.

$ chmod a+x /etc/cron.daily/columbus_python_cleanup

The script will be executed daily, but the cleanup command will only be executed if the number of python processes exceeds 10.

FuseTalk Basic Edition v4.0 - © 1999-2021 FuseTalk Inc. All rights reserved.