![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Please Help me with this ..High Priority! | balaji_gopal | Shell Programming and Scripting | 0 | 05-28-2008 12:14 PM |
| change priority of stream | gogogo | SUN Solaris | 2 | 11-28-2006 08:11 PM |
| urgent help required on changing process priority using nice | gshuttleworth | HP-UX | 1 | 07-07-2006 01:09 PM |
| change priority of packages | RellioN | UNIX for Dummies Questions & Answers | 0 | 07-01-2005 11:50 PM |
| Increasing priority of a process | jyotipg | UNIX for Advanced & Expert Users | 2 | 06-20-2003 06:20 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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);
}
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
|
|||
|
|||
|
Thanks,
I will try this Monday morning. |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|