task priorities

Computer builds, hardware and software discussion or troubleshooting, including peripherals. Essentially a general place to talk about desktop computers.
Locked
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

task priorities

Post by Red Squirrel »

You know how in windows you can set priorities for processes, is there something like this in linux? If yes is there a way to specify the priority when a command is executed?


I have cron jobs for backups, but right now they just make the server die until they're done. I want to be able to make it so they're idle and dont cause major slowdowns. I'll be in the middle of something and all of a sudden I hit refresh and it just gets all slow and I want to eliminate that.

Archived topic from Anythingforums, old topic ID:1186, old post ID:14980
Honk if you love Jesus, text if you want to meet Him!
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

task priorities

Post by megaspaz »

Red Squirrel wrote: You know how in windows you can set priorities for processes, is there something like this in linux?  If yes is there a way to specify the priority when a command is executed?


I have cron jobs for backups, but right now they just make the server die until they're done.  I want to be able to make it so they're idle and dont cause major slowdowns.  I'll be in the middle of something and all of a sudden I hit refresh and it just gets all slow and I want to eliminate that.
look at using nice or renice.

http://www.ece.arizona.edu/help/computer/f...ix/priority.php

both also have man pages... 'man nice' or 'man renice'

Archived topic from Anythingforums, old topic ID:1186, old post ID:14989
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

task priorities

Post by Red Squirrel »

That works for simple commands but not complex ones, is there an other way by any chance? Or is there a way to obtain the process ID automaticly so I can use renice? (This is in a bash script)

Archived topic from Anythingforums, old topic ID:1186, old post ID:14991
Honk if you love Jesus, text if you want to meet Him!
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

task priorities

Post by megaspaz »

Red Squirrel wrote: That works for simple commands but not complex ones, is there an other way by any chance? Or is there a way to obtain the process ID automaticly so I can use renice? (This is in a bash script)
yeah. you could write a script that uses the ps command piping the output to grep to find a process by name and then parse the columns to get it's pid then use renice on that pid... or something along those lines.

output of 'ps -el':

Code: Select all

   F S   UID   PID  PPID  C PRI  NI ADDR    SZ WCHAN  TTY          TIME CMD
100 S     0     1     0  0  75   0    -   342 schedu ?        00:00:04 init
040 S     0     2     1  0  75   0    -     0 contex ?        00:00:00 keventd
040 S     0     3     1  0  75   0    -     0 schedu ?        00:00:00 kapmd
040 S     0     4     1  0  94  19    -     0 ksofti ?        00:00:00 ksoftirqd_CPU0
040 S     0     5     1  0  75   0    -     0 schedu ?        00:00:00 kswapd
040 S     0     6     1  0  85   0    -     0 bdflus ?        00:00:00 bdflush
040 S     0     7     1  0  75   0    -     0 schedu ?        00:00:00 kupdated
040 S     0     8     1  0  85   0    -     0 md_thr ?        00:00:00 mdrecoveryd
040 S     0    12     1  0  75   0    -     0 end    ?        00:00:01 kjournald
040 S     0    91     1  0  75   0    -     0 end    ?        00:00:00 khubd
040 S     0   804     1  0  76   0    -   993 schedu ?        00:00:00 webconfd
040 S     0  1053     1  0  75   0    -   357 schedu ?        00:00:00 syslogd
140 S     0  1058     1  0  75   0    -   341 do_sys ?        00:00:00 klogd
140 S     0  1157     1  0  75   0    -   374 schedu ?        00:00:00 cardmgr
040 S     0  1169     1  0  60 -20    -     0 end    ?        00:00:10 kdldrd/dpc
040 S     0  1170     1  0  65 -10    -     0 end    ?        00:00:00 kdldrd/wrk
140 S     0  1206     1  0  75   0    -   340 schedu ?        00:00:00 apmd
040 S     0  1408     1  0  65 -10    -     0 end    ?        00:00:00 kdldrd/eth1
140 S     0  1413     1  0  75   0    -   537 schedu ?        00:00:00 xinetd
040 S     4  1582     1  0  75   0    -   709 schedu ?        00:00:00 lpd
140 S     0  1602     1  0  75   0    -   350 schedu ?        00:00:00 gpm
040 S     0  1620     1  0  75   0    -   386 schedu ?        00:00:00 crond
140 S    43  1727     1  0  75   0    -  4543 schedu ?        00:00:18 xfs
140 S     0  1745     1  0  75   0    -  1228 schedu ?        00:00:00 smbd
140 S     0  1750     1  0  75   0    -   963 schedu ?        00:00:00 nmbd
040 S     2  1786     1  0  75   0    -   351 schedu ?        00:00:00 atd
140 S     0  1800     1  0  75   0    -   573 schedu ?        00:00:00 lisa
100 S     0  1826     1  0  76   0    -   336 schedu tty1     00:00:00 mingetty
100 S     0  1827     1  0  76   0    -   336 schedu tty2     00:00:00 mingetty
100 S     0  1828     1  0  76   0    -   336 schedu tty3     00:00:00 mingetty
100 S     0  1829     1  0  76   0    -   336 schedu tty4     00:00:00 mingetty
100 S     0  1830     1  0  76   0    -   336 schedu tty5     00:00:00 mingetty
100 S     0  1831     1  0  76   0    -   336 schedu tty6     00:00:00 mingetty
100 S     0  1832     1  0  75   0    -   601 schedu ?        00:00:00 kdm
100 R     0  1840  1832  0  75   0    - 78341 -      ?        00:06:51 X
140 S     0  1841  1832  0  76   0    -   818 wait4  ?        00:00:00 kdm
100 S   500  1854  1841  0  75   0    -   562 wait4  ?        00:00:00 startkde
040 S   500  1938     1  0  75   0    -  5432 schedu ?        00:00:00 kdeinit
040 S   500  1941     1  0  75   0    -  5460 schedu ?        00:00:02 kdeinit
040 S   500  1944     1  0  75   0    -  5956 schedu ?        00:00:00 kdeinit
040 S   500  1946     1  0  75   0    -  7091 schedu ?        00:00:17 kdeinit
040 S   500  1953     1  0  75   0    -  6290 schedu ?        00:00:01 kdeinit
040 S   500  1955     1  0  75   0    -  6207 schedu ?        00:01:26 kdeinit
000 S   500  1964  1938  0  75   0    -  1887 schedu ?        00:00:03 artsd
040 S   500  1967     1  0  75   0    -  6157 schedu ?        00:00:02 kdeinit
040 S   500  1977     1  0  75   0    -  7201 schedu ?        00:00:01 kdeinit
000 S   500  1978  1854  0  75   0    -   335 schedu ?        00:00:00 kwrapper
040 S   500  1980     1  0  75   0    -  5943 schedu ?        00:00:00 kdeinit
040 S   500  1981  1938  0  75   0    -  6420 schedu ?        00:00:21 kdeinit
040 S   500  1984     1  0  75   0    -  6746 schedu ?        00:00:06 kdeinit
040 S   500  1986     1  0  75   0    -  7409 schedu ?        00:00:15 kdeinit
000 S   500  1993  1984  0  75   0    -  5994 schedu ?        00:00:04 ktraynetworker
000 S   500  1994  1938  0  76   0    -   555 wait4  ?        00:00:00 xscreensaver_st
100 S   500  1997  1994  0  75   0    -   938 schedu ?        00:00:02 xscreensaver
040 S   500  2004     1  0  75   0    -  6252 schedu ?        00:00:01 kdeinit
040 S   500  2007     1  0  75   0    -  6161 schedu ?        00:00:00 kdeinit
040 S   500  2008     1  0  75   0    -  6321 schedu ?        00:00:01 kdeinit
000 R   500  2011  1938  0  75   0    -  3854 -      ?        00:02:59 gkrellm
040 S   500  2015     1  0  75   0    -  6150 schedu ?        00:00:01 kalarmd
040 S   500  2041     1  0  75   0    -  6268 schedu ?        00:00:01 kdeinit
040 S   500  4358  1938  0  75   0    -  5503 schedu ?        00:00:00 kdeinit
140 S    99  4935  1745  0  75   0    -  1354 schedu ?        00:00:03 smbd
040 R   500  4997  1938  2  75   0    -  9425 -      ?        00:00:05 kdeinit
040 S   500  5001  1938  0  75   0    -  5602 schedu ?        00:00:00 kdeinit
040 S   500  5003  1938  0  75   0    -  5602 schedu ?        00:00:00 kdeinit
040 S   500  5004  1938  0  75   0    -  5602 schedu ?        00:00:00 kdeinit
040 S   500  5007  1938  0  75   0    -  5602 schedu ?        00:00:00 kdeinit
040 S   500  5009  1938  0  75   0    -  5602 schedu ?        00:00:00 kdeinit
040 R   500  5011  1938  6  75   0    -  6597 -      ?        00:00:00 kdeinit
000 S   500  5012  5011  0  75   0    -   631 wait4  pts/1    00:00:00 bash
000 R   500  5041  5012  0  75   0    -   784 -      pts/1    00:00:00 ps
the pid is in the 4th column. the current nice value of a process is the 8th column.

output of using ps and piping the output to grep, using 'ps -el | grep nmbd' to find the nmbd process:

Code: Select all

140 S     0  1750     1  0  75   0    -   963 schedu ?        00:00:00 nmbd
parse the output for the pid in the 4th column and use renice on that.

Archived topic from Anythingforums, old topic ID:1186, old post ID:15027
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

task priorities

Post by Red Squirrel »

But would't I need like an if statement of some sort for that? I'd basically have to write a C++ program, too much trouble for a little issue. I can just make the backups happen less often, like maybe only 10 times a day or something.

Archived topic from Anythingforums, old topic ID:1186, old post ID:15037
Honk if you love Jesus, text if you want to meet Him!
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

task priorities

Post by megaspaz »

Red Squirrel wrote: But would't I need like an if statement of some sort for that? I'd basically have to write a C++ program, too much trouble for a little issue.   I can just make the backups happen less often, like maybe only 10 times a day or something.
no you could make a bash script.... or you could be lazy and just make the back ups happen less often. :P

Archived topic from Anythingforums, old topic ID:1186, old post ID:15052
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

task priorities

Post by Red Squirrel »

I can use if statements and string handling (to parse the output and extract the number) in bash? That's kind of interesting.

but I'll do it the lazy way anyway. Besides every 20 minutes might be a little paranoid of me anyway, and it generates ton of emails for nothing. (cron emails)

Archived topic from Anythingforums, old topic ID:1186, old post ID:15053
Honk if you love Jesus, text if you want to meet Him!
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

task priorities

Post by megaspaz »

Red Squirrel wrote: I can use if statements and string handling (to parse the output and extract the number) in bash?    That's kind of interesting.

but I'll do it the lazy way anyway. Besides every 20 minutes might be a little paranoid of me anyway, and it generates ton of emails for nothing.  (cron emails)
yes you can use if statements in bash. remember that path problem you posted, and i gave the answer to that? i told you to put a line after the if/fi statement? yeah, that's an if statement in bash.

http://www.tldp.org/LDP/abs/abs-guide.pdf

download and have fun learning about using bash. ;)

Archived topic from Anythingforums, old topic ID:1186, old post ID:15054
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

task priorities

Post by Red Squirrel »

Cool did not realize it was possible to do so much in bash figured it was just the linux version of batch files. :D

Archived topic from Anythingforums, old topic ID:1186, old post ID:15055
Honk if you love Jesus, text if you want to meet Him!
megaspaz
Posts: 340
Joined: Wed Dec 18, 2002 10:08 pm

task priorities

Post by megaspaz »

yep, you can use loop constructs and there's already pre-built file attribute checks that you can use in your conditional/loop statements.

Archived topic from Anythingforums, old topic ID:1186, old post ID:15057
Image
Resistance is futile...

Registered Linux User #321628
Anime/Toon Avatars
Other Cool Forums

"Never hold your farts in. They travel up your spine, into your brain, and that's where you get s**tty ideas from..." - Woyaya - January 10, 2004
closet geek
Posts: 35
Joined: Thu Dec 18, 2003 8:40 am

task priorities

Post by closet geek »

Are you using an if loop to grab data from the fourth column (sorry am skim reading). No need for that just do something like:

ps -el | awk '{print $4}'

cg

Archived topic from Anythingforums, old topic ID:1186, old post ID:18908
Locked