Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Automate a task

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-12-2017   -   Original Discussion by Samiran Dam
Samiran Dam's Unix or Linux Image
Samiran Dam Samiran Dam is offline
Registered User
 
Join Date: Dec 2017
Last Activity: 12 December 2017, 4:46 AM EST
Location: Bangalore
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Automate a task

Dear All,

I am relatively new to UNIX and wanted to accomplish a simple task which should be automated. That's why I need your help. I shall briefly describe what I want.

Basically, there is a process (X) (related to a particular software which I am using in my system) which automatically starts after some time and eats up a lot of resources resulting in slowing up other necessary processes running. So all I want is to -
STEP-1: periodically (it is better if I can set the the interval duration) check whether process-X has started or not
STEP-2: obtain the PID of the process-X
STEP-3: execute: "kill -9 <PID of process-X>"

And these three steps, I want to write as a script and that script should automatically check the status of process-X and take necessary action as long as my system is up.

Could anybody please help me to accomplish this.

- Sam.
Sponsored Links
    #2  
Old Unix and Linux 12-12-2017   -   Original Discussion by Samiran Dam
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is online now Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 21 May 2018, 1:01 AM EDT
Location: San Jose, CA, USA
Posts: 11,295
Thanks: 633
Thanked 3,929 Times in 3,364 Posts
Instead of repeatedly killing process (X); why not just use nice when you start it so it will run at a lower priority and use less system resources when your necessary processes are running at normal priority.
Sponsored Links
    #3  
Old Unix and Linux 12-12-2017   -   Original Discussion by Samiran Dam
Samiran Dam's Unix or Linux Image
Samiran Dam Samiran Dam is offline
Registered User
 
Join Date: Dec 2017
Last Activity: 12 December 2017, 4:46 AM EST
Location: Bangalore
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Don Cragun View Post
Instead of repeatedly killing process (X); why not just use nice when you start it so it will run at a lower priority and use less system resources when your necessary processes are running at normal priority.
Thank you, Don Cragun for replying.

The problem here is - process X does not get initiated by the user, it is started from within another master process which is the main design software (installed in our company's server, so I don't have much access to that other than launching it and working on it) I am using in my system. Now, I don't know on what basis process X is started. So, everyday morning, I used to kill process X and continue with my work. If am in front of my workstation, I can manually check the status of process X and kill it whenever necessary. However, if it starts overnight then it slows don the progress of other simulations being run in the main software. So, I wanted to have a local work around to this problem so that what I am doing manually (when I am in front of the workstation) can be done automatically. And I don't have to bother about it forever Linux
    #4  
Old Unix and Linux 12-12-2017   -   Original Discussion by Samiran Dam
apmcd47's Unix or Linux Image
apmcd47 apmcd47 is offline
Registered User
 
Join Date: Feb 2011
Last Activity: 18 May 2018, 5:33 AM EDT
Posts: 341
Thanks: 16
Thanked 94 Times in 89 Posts
Then look up renice.

From the man page:


Code:
DESCRIPTION
       renice alters the scheduling priority of one or more running processes.
       The first argument is the priority value to be used.  The  other  argu‐
       ments  are  interpreted as process IDs (by default), process group IDs,
       user IDs, or user names.  renice'ing a process group  causes  all  pro‐
       cesses  in the process group to have their scheduling priority altered.
       renice'ing a user causes all processes owned by the user to have  their
       scheduling priority altered.

Sponsored Links
    #5  
Old Unix and Linux 12-12-2017   -   Original Discussion by Samiran Dam
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 20 May 2018, 6:10 PM EDT
Location: Simplicity
Posts: 4,076
Thanks: 351
Thanked 1,374 Times in 1,238 Posts
What kind of resources does it consume, and what are the thesholds?
We can measure memory, CPU time, elapsed time.
What is your OS (run uname)?
Sponsored Links
    #6  
Old Unix and Linux 12-12-2017   -   Original Discussion by Samiran Dam
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is online now Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 21 May 2018, 1:01 AM EDT
Location: San Jose, CA, USA
Posts: 11,295
Thanks: 633
Thanked 3,929 Times in 3,364 Posts
Quote:
Originally Posted by Samiran Dam View Post
Thank you, Don Cragun for replying.

The problem here is - process X does not get initiated by the user, it is started from within another master process which is the main design software (installed in our company's server, so I don't have much access to that other than launching it and working on it) I am using in my system. Now, I don't know on what basis process X is started. So, everyday morning, I used to kill process X and continue with my work. If am in front of my workstation, I can manually check the status of process X and kill it whenever necessary. However, if it starts overnight then it slows don the progress of other simulations being run in the main software. So, I wanted to have a local work around to this problem so that what I am doing manually (when I am in front of the workstation) can be done automatically. And I don't have to bother about it forever Linux
What operating system are you using?

What shell are you using?

When you are in front of your workstation and manually kill process X, please show us exactly what commands do you type into your shell to kill process X (in CODE tags). If you want a script to replace what you're doing manually, it is always great to actually know what you do manually! Show us the output produced by each step. Tell us what you use from each step as input to the next step.

Do you really have to use kill -9 PID? Doesn't kill PID work?
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
task hernand Shell Programming and Scripting 10 05-27-2011 07:42 AM
Need a help to automate a task Renjesh Shell Programming and Scripting 4 12-08-2010 08:14 AM
Script that can Automate Printer adding task in HP-UX servers AnilKPatnaik UNIX for Advanced & Expert Users 2 08-11-2009 11:04 AM
Parse an XML task list to create each task.xml file MissI Shell Programming and Scripting 3 11-11-2008 01:20 PM
comment and Uncomment single task out of multiple task madhusmita Shell Programming and Scripting 9 06-18-2008 09:42 AM



All times are GMT -4. The time now is 01:02 AM.