setpriority() question

setpriority() question

Post by <ra.. » Tue, 22 Jun 1999 04:00:00



Hi,

I'm trying to set a higher scheduling priority for a "real-time" data gathering
program.
The program has owner root and the sbit is set.
Root privileges will be dropped after the priority is improved.

However, the following piece of code always sets priority to 0 which
is returned by getpriority().
How can I get the highest priority available ?

  user=getuid();
  fprintf(stderr,">>Running as id %d\n",user);
  if( geteuid() != 0 ){
    fprintf(stderr,">>Not setuid root..\n");
  }
  else{
    if( setuid(0)!=0 )
      perror("setuid root");
    ret=getpriority(PRIO_USER, 0);
    fprintf(stderr,">>Setting process priority to: %d\n",ret);
    if( setpriority(PRIO_PROCESS, 0, ret) !=0 )
      perror("setpriority");
    if( setuid(user) !=0 )
      perror("setuid user");
  }

 
 
 

setpriority() question

Post by F.R.M.Barn » Tue, 22 Jun 1999 04:00:00


: However, the following piece of code always sets priority to 0 which
: is returned by getpriority().
: How can I get the highest priority available ?

setpriority( PRIO_PROCESS, 0, -20 );

HTH,
  Fred.
--
+----------------------------------------------------------------------+
| Fred Barnes, CS Student, UKC                http://teddy.xylene.com/ |

+----------------------------------------------------------------------+

 
 
 

setpriority() question

Post by <ra.. » Thu, 24 Jun 1999 04:00:00


well, I could hardcode the priority like in

setpriority( PRIO_PROCESS, 0, -20)

but I understood that getpriority() would return the highest available
for the process. That is , if run setuid root I could get -20, if not
I would get 0.

By the way, as this is not conformant to POSIX, is there another (POSIX)
way to do this ?

Tnx in advance.

 
 
 

setpriority() question

Post by F.R.M.Barn » Thu, 24 Jun 1999 04:00:00


: By the way, as this is not conformant to POSIX, is there another (POSIX)
: way to do this ?

sched_setparam() seems to be POSIX, and I guess you can change the
priority with this, although on my Linux sched_get_priority_max/min
both returned 0...

HTH,
  Fred.
--
+----------------------------------------------------------------------+
| Fred Barnes, CS Student, UKC                http://teddy.xylene.com/ |

+----------------------------------------------------------------------+

 
 
 

1. setpriority() equivalent in Solaris2

Hi,

I hope this isn't an FAQ... Exactly how do I use priocntl() in Solaris2
to "mimic" the behaviour of setpriority()?

truss'ing a test program indicates that I should do something like

   priocntl(P_PID, aaa, PC_GETPARMS, (caddr_t)&bbb);
   .
   .
   .
   priocntl(P_PID, aaa, PC_GETCID, (caddr_t)&ccc);
   .
   .
   .
   priocntl(P_PID, ddd, PC_GETPARMS,( caddr_t)&bbb);
   .
   .
   .

I haven't examined this a lot yet, I'm hoping someone already knows this,
and can save me some time! :)

Thanks,

-- Leif

2. 2 warning messages upon bootup

3. setpriority -> priocntl

4. Linux 2.0.27 as SLIP source

5. Linux Kernel Patch; setpriority

6. Probleme avec XFree

7. get/setpriority w/o bsd compatibility?

8. L 10 10 10 10...

9. the use of getpriority and setpriority

10. setpriority() fails with EPERM instead of EACCES

11. setpriority PPID

12. setpriority

13. Solaris equivalent to SunOS getpriority/setpriority