Changing the priority of a program


 
Thread Tools Search this Thread
Top Forums Programming Changing the priority of a program
# 1  
Old 12-15-2001
Changing the priority of a program

I have the following code in a file:

task ph_cause_sound()
{
char sys_call[100];
int ret_val;

sprintf (sys_call, "/usr/local/bin/test_sound ");
ret_val = system(sys_call);
}


test_sound is a script file that contains one line:
nice --20 /usr/local/bin/vmod4dSOUND



What is suppose to happen is three phone rings go out a sound card port. A set of headphones are connected to this port. I have 7 other processes running (all have a nice value of 20). If I run has root and just type in at the command line "/usr/local/bin/vmod4dSOUND" it sounds garbled on the headphones. It also sounds garbled when ph_cause_sound executes system call. More then likly because all are running at the same priority level (or close to it).

Now the part that confuses me. And I hope I can explain this correctly. If I type "nice --20 /usr/local/bin/vmod4dSOUND" or "/usr/local/bin/test_sound" at the command line everything sounds great. This cause nice to be 0 and at a higher priority.

I performed a ps -ef|grep vmod4dSOUND when the rings are to be executed and a nice value of 20 is shown on the times I had typed in "usr/local/bin/vmod4dSOUND" and when ph_cause_sound executed the command to run test_sound.

I'm also seeing the following under the CMD column (when I run ps -ef) when the ph_cause_sound executes the command to run test_sound:
sh -c /usr/local/bin/vmod4dSOUND
/usr/local/bin/vmod4dSOUND

I know from the above that the POSIX shell (/usr/bin/sh) is running the command when it is executed by ph_cause_sound.

But, while running under bash, when I typed at the command line "nice --20 /usr/local/bin/vmod4dSOUND" or "usr/local/bin/test_sound" a nice value of 0 is shown (a higher priority which is what I want). And under CMD column only the following is shown:
/usr/local/bin/vmod4dSOUND

All I want is to execute the command to run the test_sound file from ph_cause_sound with a nice value of 0. Any suggestions would be much appreciated.
# 2  
Old 12-16-2001
Adding a negative increment to a process's nice value requires that the process have an effective uid of root. Is this program running suid to root? When bash starts up in that state, it will abandon the root power unless -p has been specified. Other modern shells will also have features to resist running scripts while suid'ed. My guess is that this happened to you.

Does /usr/local/bin/vmod4dSOUND need root power? If it can run as an ordinary user, pick one, let's say it's uid 4. Now write a program like:
Code:
int main(int argc, char *argv[])
{
      nice(-20);
      setuid(4);
      execl("/usr/local/bin/vmod4dSOUND", "vmod4dSOUND", NULL);
}

And call this, perhaps, runvmod4dSOUND. It must be owned by root and have the setuid bit on:
chown root runvmod4SOUND
chmod 4755 runvmod4SOUND

Now you have a program that can run your sound and it is already setuid to root. So now the invoking program can be an ordinary user.

And when you invoke it, just do...
system("/usr/local/bin/runvmod4dSOUND");

You don't need to copy the string into an array the way you are doing.
# 3  
Old 12-16-2001
Thanks,

I will try this Monday morning.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Retreiving multiple files by changing a parameter with one program

Hi all, I am using following command: perl program.pl input.txt output.txt CUTOFF 3 > groups_3.txt containing program.pl, two files (input.txt, output.txt) and getting output in groups_3.txt: But, I wish to have 30 files corresponding to each CUTOFF ranging from 0 to 30 using the same... (1 Reply)
Discussion started by: bioinfo
1 Replies

2. Red Hat

The priority of the log

Hi, I can't find the priority in my logs, which under the catalogue of /var/log/lmessages. For example, if the log below occur on my machine, there is no <30>. What should I do if I want to see <30> . <30>Oct 9 22:33:20 hlfedora auditd: The audit daemon is exiting. (0 Replies)
Discussion started by: zhaoyy
0 Replies

3. Programming

Changing the way arguments are read from program

I have the following piece of code. Currently the command line arguments are passed as shown below using the "= "sign. I capture the name of the argument, for example vmod and it's corresponding user parameter which is jcdint-z30.cmd. ./raytrac vmod=jcdint-z30.cmd srFile=jcdint.sr Now I want... (12 Replies)
Discussion started by: kristinu
12 Replies

4. Red Hat

DNS priority

Hi All, Is this correct on DNS searching? (1st priority) /etc/hosts (2nd p.) /etc/resolv.conf Are there more things that I didn't know? Thank you for any comments you may add. (5 Replies)
Discussion started by: itik
5 Replies

5. AIX

priority for process

hi how to change the priority of a process for eg.if a,b,c these there process are running and if i have to give the b process as high priority and high severe level what should i do (3 Replies)
Discussion started by: senmak
3 Replies

6. Programming

kill priority

hello everybody! i would like to post a question. If i embed in my C code the command kill(9,pid) inside an if command. Is this command(kill) executed in any way. Both if the if is true and false. Does kill have greater priority than the if command. thanx in advance! (5 Replies)
Discussion started by: nicos
5 Replies

7. UNIX for Advanced & Expert Users

IRQ priority in FC9

Hi, I want to increase IRQ4 priority to maximum in Fedora core 9 (kernel version 2.6.25.11-97).If anybody knows plz help me.... I will be very thankful .. regards, Raj (0 Replies)
Discussion started by: rajuprade
0 Replies

8. Shell Programming and Scripting

Please Help me with this ..High Priority!

Hi, I am a nw bie to Schell Scripting, i have a same king of requirement as posted above. my input file is also a log file as below..... 28.05.2008 07:02:56,105 INFO Validation request recieved 28.05.2008 07:03:57,856 INFO 0:01:13.998 Response sent with: <?xml version="1.0"... (0 Replies)
Discussion started by: balaji_gopal
0 Replies

9. HP-UX

urgent help required on changing process priority using nice

Hi folks, Hope you can help me. I have a process that is currently running at nice 20 and need it to run faster (-10?). How do I change the process using nice? I have the process number and thought it would be along the lines of; nice -10 process_id but it doesn't seem to like that. (1 Reply)
Discussion started by: gshuttleworth
1 Replies

10. UNIX for Advanced & Expert Users

Increasing priority of a process

Hi! Experts, Is there anyway to incerase the priority of a process which is already started and running??.. I think nice can used for increase priority when we start the process.. But donno how to do when its already running.. Any help would be apreciated.. Jyoti (2 Replies)
Discussion started by: jyotipg
2 Replies
Login or Register to Ask a Question