From: Manish Katiyar <mkatiyar@gmail.com>
To: "Srinivas G." <srinivasg@esntechnologies.co.in>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: Unable set the priority for a pthread through pthread_setschedparam
Date: Tue, 3 Feb 2009 11:14:54 +0530 [thread overview]
Message-ID: <ea11fea30902022144t5a566d8br58ba711400e3ab0a@mail.gmail.com> (raw)
In-Reply-To: <F5BA82141F7AA94885B9643C77EEA5F2103C73@mail.esntechnologies.co.in>
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
>
next prev parent reply other threads:[~2009-02-03 5:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-03 4:48 Unable set the priority for a pthread through pthread_setschedparam Srinivas G.
2009-02-03 5:44 ` Manish Katiyar [this message]
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ea11fea30902022144t5a566d8br58ba711400e3ab0a@mail.gmail.com \
--to=mkatiyar@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
--cc=srinivasg@esntechnologies.co.in \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).