* Unable set the priority for a pthread through pthread_setschedparam
@ 2009-02-03 4:48 Srinivas G.
2009-02-03 5:44 ` Manish Katiyar
2009-02-04 1:49 ` Glynn Clements
0 siblings, 2 replies; 9+ messages in thread
From: Srinivas G. @ 2009-02-03 4:48 UTC (permalink / raw)
To: linux-c-programming
Dear All,
I have written a small thread program in C using the pthreads. I am able
to set the threads priority with pthread_setschedparam API when I login
as ROOT. If I login as a normal user other than ROOT, then the API
returns the error number 1 (EPERM).
Please let me know whether a normal user can set the pthreads priority
with pthread_setschedparam API or not.
Here is the sample code for testing.
/*
* Creates two threads, one printing 10 "a"s,
* the other printing 10 "b"s.
* Illustrates: thread creation, thread joining.
*/
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#include "pthread.h"
#include <errno.h>
void * process(void * arg)
{
int i;
fprintf(stderr, "Starting process %s\n", (char *) arg);
for (i = 0; i < 10; i++) {
write(1, (char *) arg, 1);
}
fprintf(stderr,"\n");
return NULL;
}
int main()
{
int retcode;
pthread_t th_a, th_b;
void * retval;
struct sched_param sp;
int esnRetVal = 0;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
retcode = pthread_create(&th_a, &attr, process, "a");
if (retcode != 0) fprintf(stderr, "create a failed %d\n", retcode);
sp.sched_priority = 30;
esnRetVal = pthread_setschedparam(th_a, SCHED_RR, &sp);
if(esnRetVal != 0)
{
printf("Failed to set the pthread sched param! esnRetVal = %d errno
= %d\n", esnRetVal, errno);
return -1;
}
retcode = pthread_create(&th_b, NULL, process, "b");
if (retcode != 0) fprintf(stderr, "create b failed %d\n", retcode);
retcode = pthread_join(th_a, &retval);
if (retcode != 0) fprintf(stderr, "join a failed %d\n", retcode);
retcode = pthread_join(th_b, &retval);
if (retcode != 0) fprintf(stderr, "join b failed %d\n", retcode);
return 0;
}
Thanks in advance.
With Regards,
Srinivas G
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Unable set the priority for a pthread through pthread_setschedparam
2009-02-03 4:48 Unable set the priority for a pthread through pthread_setschedparam Srinivas G.
@ 2009-02-03 5:44 ` Manish Katiyar
2009-02-03 6:27 ` Srinivas G.
2009-02-04 1:49 ` Glynn Clements
1 sibling, 1 reply; 9+ messages in thread
From: Manish Katiyar @ 2009-02-03 5:44 UTC (permalink / raw)
To: Srinivas G.; +Cc: linux-c-programming
On Tue, Feb 3, 2009 at 10:18 AM, Srinivas G.
<srinivasg@esntechnologies.co.in> wrote:
> Dear All,
>
> I have written a small thread program in C using the pthreads. I am able
> to set the threads priority with pthread_setschedparam API when I login
> as ROOT. If I login as a normal user other than ROOT, then the API
> returns the error number 1 (EPERM).
>
> Please let me know whether a normal user can set the pthreads priority
> with pthread_setschedparam API or not.
The man page says it all
!EPERM!
the calling process does not have superuser permissions
you cannot unless you have superuser permissions.
Thanks -
Manish
>
> Here is the sample code for testing.
>
> /*
> * Creates two threads, one printing 10 "a"s,
> * the other printing 10 "b"s.
> * Illustrates: thread creation, thread joining.
> */
>
> #include <stddef.h>
> #include <stdio.h>
> #include <unistd.h>
> #include "pthread.h"
> #include <errno.h>
>
> void * process(void * arg)
> {
> int i;
> fprintf(stderr, "Starting process %s\n", (char *) arg);
> for (i = 0; i < 10; i++) {
> write(1, (char *) arg, 1);
> }
> fprintf(stderr,"\n");
>
> return NULL;
> }
>
> int main()
> {
> int retcode;
> pthread_t th_a, th_b;
> void * retval;
> struct sched_param sp;
> int esnRetVal = 0;
> pthread_attr_t attr;
>
> pthread_attr_init(&attr);
> pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
>
> retcode = pthread_create(&th_a, &attr, process, "a");
> if (retcode != 0) fprintf(stderr, "create a failed %d\n", retcode);
>
> sp.sched_priority = 30;
> esnRetVal = pthread_setschedparam(th_a, SCHED_RR, &sp);
> if(esnRetVal != 0)
> {
> printf("Failed to set the pthread sched param! esnRetVal = %d errno
> = %d\n", esnRetVal, errno);
> return -1;
> }
>
> retcode = pthread_create(&th_b, NULL, process, "b");
> if (retcode != 0) fprintf(stderr, "create b failed %d\n", retcode);
>
> retcode = pthread_join(th_a, &retval);
> if (retcode != 0) fprintf(stderr, "join a failed %d\n", retcode);
>
> retcode = pthread_join(th_b, &retval);
> if (retcode != 0) fprintf(stderr, "join b failed %d\n", retcode);
>
> return 0;
> }
>
> Thanks in advance.
>
> With Regards,
> Srinivas G
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: Unable set the priority for a pthread through pthread_setschedparam
2009-02-03 5:44 ` Manish Katiyar
@ 2009-02-03 6:27 ` Srinivas G.
2009-02-03 8:11 ` Manish Katiyar
0 siblings, 1 reply; 9+ messages in thread
From: Srinivas G. @ 2009-02-03 6:27 UTC (permalink / raw)
To: Manish Katiyar; +Cc: linux-c-programming
> The man page says it all
>
> !EPERM!
> the calling process does not have superuser
> permissions
>
> you cannot unless you have superuser permissions.
>
Dear Manish,
Thanks for the information.
I have seen the man pages and find the following.
EPERM The caller does not have appropriate privileges to set the
specified
scheduling policy and parameters.
I have tried to set the super user permissions to a normal user through
user and groups. However I found there are lot of different groups
exists like
adm
apache
avahi
bin
daemon
dbus
dip
etc.
Which groups shall I need to select for setting the super user
permissions?
Thanks in advance.
Thanks and Regards,
Srinivas G
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Unable set the priority for a pthread through pthread_setschedparam
2009-02-03 6:27 ` Srinivas G.
@ 2009-02-03 8:11 ` Manish Katiyar
0 siblings, 0 replies; 9+ messages in thread
From: Manish Katiyar @ 2009-02-03 8:11 UTC (permalink / raw)
To: Srinivas G.; +Cc: linux-c-programming
On Tue, Feb 3, 2009 at 11:57 AM, Srinivas G.
<srinivasg@esntechnologies.co.in> wrote:
>> The man page says it all
>>
>> !EPERM!
>> the calling process does not have superuser
>> permissions
>>
>> you cannot unless you have superuser permissions.
>>
>
> Dear Manish,
>
> Thanks for the information.
>
> I have seen the man pages and find the following.
>
> EPERM The caller does not have appropriate privileges to set the
> specified
> scheduling policy and parameters.
>
> I have tried to set the super user permissions to a normal user through
> user and groups. However I found there are lot of different groups
one with id 0 .. see /etc/group
Thanks -
Manish
> exists like
> adm
> apache
> avahi
> bin
> daemon
> dbus
> dip
> etc.
>
> Which groups shall I need to select for setting the super user
> permissions?
>
> Thanks in advance.
>
> Thanks and Regards,
> Srinivas G
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Unable set the priority for a pthread through pthread_setschedparam
2009-02-03 4:48 Unable set the priority for a pthread through pthread_setschedparam Srinivas G.
2009-02-03 5:44 ` Manish Katiyar
@ 2009-02-04 1:49 ` Glynn Clements
2009-02-04 6:31 ` Srinivas G.
1 sibling, 1 reply; 9+ messages in thread
From: Glynn Clements @ 2009-02-04 1:49 UTC (permalink / raw)
To: Srinivas G.; +Cc: linux-c-programming
Srinivas G. wrote:
> I have written a small thread program in C using the pthreads. I am able
> to set the threads priority with pthread_setschedparam API when I login
> as ROOT. If I login as a normal user other than ROOT, then the API
> returns the error number 1 (EPERM).
>
> Please let me know whether a normal user can set the pthreads priority
> with pthread_setschedparam API or not.
Yes, subject to certain restrictions, which are detailed in the
sched_setscheduler(2) manpage.
In particular, a non-privileged process cannot set the real-time
priority higher than its RLIMIT_RTPRIO setting. You can change this
with an "rtprio" entry in /etc/security/limits.conf (settings are
applied on login, so changes won't affect existing login sessions).
Privilege is determined by the CAP_SYS_NICE capability.
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: Unable set the priority for a pthread through pthread_setschedparam
2009-02-04 1:49 ` Glynn Clements
@ 2009-02-04 6:31 ` Srinivas G.
2009-02-04 15:32 ` ben
2009-02-04 23:07 ` Glynn Clements
0 siblings, 2 replies; 9+ messages in thread
From: Srinivas G. @ 2009-02-04 6:31 UTC (permalink / raw)
To: Glynn Clements; +Cc: linux-c-programming, Manish Katiyar
Glynn Clements wrote:
> Yes, subject to certain restrictions, which are detailed in the
> sched_setscheduler(2) manpage.
>
> In particular, a non-privileged process cannot set the real-time
> priority higher than its RLIMIT_RTPRIO setting. You can change this
> with an "rtprio" entry in /etc/security/limits.conf (settings are
> applied on login, so changes won't affect existing login sessions).
>
> Privilege is determined by the CAP_SYS_NICE capability.
Thanks Glynn.
I have tried to set the RLIMIT_RTPRIO to 100 through
/etc/security/limits.conf. It was not defined previously, so I have
defined in the following way.
domain type item value
#@srinivasg soft rtprio 100
After adding the above statement, I have restarted the system.
Then, I run my simple thread program. There is no luck. I got the same
error. I have posted the simple thread program in my first email.
What am I missing here? Please advice.
Thanks and Regards,
Srinivas G
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Unable set the priority for a pthread through pthread_setschedparam
2009-02-04 6:31 ` Srinivas G.
@ 2009-02-04 15:32 ` ben
2009-02-04 23:07 ` Glynn Clements
1 sibling, 0 replies; 9+ messages in thread
From: ben @ 2009-02-04 15:32 UTC (permalink / raw)
To: linux-c-programming
Srinivas G. a écrit :
> I have tried to set the RLIMIT_RTPRIO to 100 through
> /etc/security/limits.conf. It was not defined previously, so I have
> defined in the following way.
>
> domain type item value
> #@srinivasg soft rtprio 100
you must uncomment the line (remove the #)
then, the given group will have a soft rtprio limit to 100.
This will work, assuming your PAM configuration uses pam_limits.
> After adding the above statement, I have restarted the system.
>
> Then, I run my simple thread program. There is no luck. I got the same
> error. I have posted the simple thread program in my first email.
>
> What am I missing here? Please advice.
>
> Thanks and Regards,
> Srinivas G
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: Unable set the priority for a pthread through pthread_setschedparam
2009-02-04 6:31 ` Srinivas G.
2009-02-04 15:32 ` ben
@ 2009-02-04 23:07 ` Glynn Clements
2009-02-05 4:06 ` Srinivas G.
1 sibling, 1 reply; 9+ messages in thread
From: Glynn Clements @ 2009-02-04 23:07 UTC (permalink / raw)
To: Srinivas G.; +Cc: linux-c-programming, Manish Katiyar
Srinivas G. wrote:
> > Yes, subject to certain restrictions, which are detailed in the
> > sched_setscheduler(2) manpage.
> >
> > In particular, a non-privileged process cannot set the real-time
> > priority higher than its RLIMIT_RTPRIO setting. You can change this
> > with an "rtprio" entry in /etc/security/limits.conf (settings are
> > applied on login, so changes won't affect existing login sessions).
> >
> > Privilege is determined by the CAP_SYS_NICE capability.
>
> Thanks Glynn.
>
> I have tried to set the RLIMIT_RTPRIO to 100 through
> /etc/security/limits.conf. It was not defined previously, so I have
> defined in the following way.
>
> domain type item value
> #@srinivasg soft rtprio 100
First, as Ben says, you must uncomment the line. Second, you may also
need to set the hard limit. You can use "ulimit -a" (or -aH) to check
the actual limits.
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: Unable set the priority for a pthread through pthread_setschedparam
2009-02-04 23:07 ` Glynn Clements
@ 2009-02-05 4:06 ` Srinivas G.
0 siblings, 0 replies; 9+ messages in thread
From: Srinivas G. @ 2009-02-05 4:06 UTC (permalink / raw)
To: Glynn Clements; +Cc: linux-c-programming, Manish Katiyar, Nutan C.
Glynn wrote:
> > domain type item value
> > #@srinivasg soft rtprio 100
>
> First, as Ben says, you must uncomment the line. Second, you may also
> need to set the hard limit. You can use "ulimit -a" (or -aH) to check
> the actual limits.
Thanks Glynn.
I am able to run the programs as a normal user after setting the soft as
well as hard values in /etc/security/limits.conf values. However,
without setting the hard limit, I am not able to run the programs. So,
by setting the soft and hard values to 100, I am able to run.
domain type item value
@srinivasg soft rtprio 100
@srinivasg hard rtprio 100
Thanks for the right information.
With Regards,
Srinivas G
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2009-02-05 4:06 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-03 4:48 Unable set the priority for a pthread through pthread_setschedparam Srinivas G.
2009-02-03 5:44 ` Manish Katiyar
2009-02-03 6:27 ` Srinivas G.
2009-02-03 8:11 ` Manish Katiyar
2009-02-04 1:49 ` Glynn Clements
2009-02-04 6:31 ` Srinivas G.
2009-02-04 15:32 ` ben
2009-02-04 23:07 ` Glynn Clements
2009-02-05 4:06 ` Srinivas G.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).