In order to stop the PSI application, each PSI task must be killed. To determine which tasks are active the following command should be issued.
[codesyntax lang=”bash”]
ps aux | grep gunicorn
[/codesyntax]
The application dynamically generate and issues this command.
The results of that command are listed below.
[codesyntax lang=”bash”]
ec2-user 10460 0.0 0.8 217576 17420 pts/2 S 10:59 0:00 /var/www/psi-pro/bin/python2.7 /var/www/psi-pro/bin/gunicorn -c gu.conf application ec2-user 10466 0.0 0.8 217572 17480 pts/2 S 10:59 0:00 /var/www/www.personalstyles.org/psiapp/server/venv/bin/python2.7 /var/www/www.personalstyles.org/psiapp/server/venv/bin/gunicorn -c gu.conf application ec2-user 10471 0.0 0.9 264212 19852 pts/2 S 10:59 0:00 /var/www/psi-pro/bin/python2.7 /var/www/psi-pro/bin/gunicorn -c gu.conf application ec2-user 10477 0.0 5.3 345544 109836 pts/2 S 10:59 0:01 /var/www/www.personalstyles.org/psiapp/server/venv/bin/python2.7 /var/www/www.personalstyles.org/psiapp/server/venv/bin/gunicorn -c gu.conf application ec2-user 10479 0.0 0.9 264208 19860 pts/2 S 10:59 0:00 /var/www/psi-pro/bin/python2.7 /var/www/psi-pro/bin/gunicorn -c gu.conf application ec2-user 10484 0.0 5.3 345564 109852 pts/2 S 10:59 0:01 /var/www/www.personalstyles.org/psiapp/server/venv/bin/python2.7 /var/www/www.personalstyles.org/psiapp/server/venv/bin/gunicorn -c gu.conf application ec2-user 10870 0.0 0.1 110460 2196 pts/3 S+ 12:41 0:00 grep --color=auto gunicorn
[/codesyntax]
Each task beginning with 10460 through 10870 should be killed.
Rather than type the kill command seven times a c++ program reads the captured text and generates a script to kill the associated tasks.
After the program runs the following script is created.
[codesyntax lang=”bash”]
kill 10460 kill 10466 kill 10471 kill 10477 kill 10479 kill 10484 kill 10870
[/codesyntax]
This automated task eliminates keyboarding on numerous levels plus zero mistakes are made on typing the associated task number.
This application automatically executes the shell script “kil.sh” without further intervention.
The source code for the c++ program is listed below.
[codesyntax lang=”cpp”]
//============================================================================ // Name : genKillc.cpp // Author : Mr. Arch Brooks // Date : Feb 7, 2020 // Version : 1.01 // Copyright : All rights reserved // Description : genKill in C++, Ansi-style // : // : This application finds the active PSI applications // : A shell script is dynamically created, marked as executable // : then the shell script is executed. // : All overhead files created in the process are removed. //============================================================================ #include <iostream> #include <iostream> #include <fstream> #include <cstdlib> using namespace std; int main() { /* This command finds the active PSI system and stores the results in file "ar.txt" */ system("ps aux | grep gunicorn > ar.txt"); // This command makes the "ar.txt" file an input file fstream inp("ar.txt"); // This command makes the output shell script "kil.txt" ofstream out("kil.sh"); // This variable holds the contents of the input file string line; while(!inp.eof()) // To get you all the lines in file "ar.txt". { getline(inp,line); // loads one line from the file intp the buffer line if (line.length() > 1) //If a blank line is encountered ignore it. { line = line.substr(line.find(" ") + 1, line.length());// Remove information preceding the task number line.erase(line.find(" "), line.length());// Remove the trailing information from the line variable. out << "kill " << line << endl;//generate the Kill Command } } inp.close(); out.close(); system("rm ar.txt");// Remove the input file. system("chmod +x kil.sh");// Make the script file "kil.sh" executable. system("./kil.sh");// Execute the "kil.sh" command. system("rm kil.sh");// Remove the "kil.sh" script return 0; }
[/codesyntax]
Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.