Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8574423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:28:16+00:00 2026-06-11T19:28:16+00:00

In Bash I’m trying to get the process with most %CPU. Once i get

  • 0

In Bash I’m trying to get the process with most %CPU. Once i get it, i’m using awk to evaluate if the process must be killed or just change it’s nice. Once i get the process, here’s what i’m trying to do :

awk -v awkmax="$CPU_MAX" '
{ 
  if( $3 > awkmax && $4 < 15 ) { 
    system("renice "$4"+5 -p "$1"")
  } 
  else if ( $3 > awkmax && $4 == 15 ) { 
    system("kill -9 "$1"")
    print "The process $1 has been killed.\n" 
  } 
}'

where $3 is pcpu, $4 is the nice value and $1 is the pid.

My problem is here:

system("renice "$4"+5 -p "$1"")

it doesn’t work because of the "$4"+5, which is the actual nice of the process plus 5.

How can i pass that value to renice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:28:18+00:00Added an answer on June 11, 2026 at 7:28 pm

    You have some quoting issues, the first system call should be:

    system("renice " $4 + 5 " -p " $1)
    

    And the second:

    system("kill -9 " $1)
    

    Space is the string concatenation operator in awk.

    A note on kill -9: it’s better to start with less severe signals before resorting to -9, as this doesn’t let the process do any cleaning up after it self, IIRC, start with SIGHUP (-1), then SIGINT (-2), then SIGTERM (-15), if none of these makes the process quit, then use SIGKILL (-9).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using bash, how can one get the number of files in a folder, excluding
Using bash date, I can get it to return a day of the week
using bash, I'm trying to insert a variable for the date and search a
In bash I would like to get filename from a command line string. But
In Bash, I want to get the Nth word of a string hold by
In bash, I'm using a gitprompt to show the current status of my git
Bash 4 on Linux ~ I have an array of possible values. I must
In bash when I access an array by index I get strange behavior if
#!/bin/bash # Command line look up using Google's define feature - command line dictionary
Using bash, how to find files in a directory structure except for *.xml files?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.