1 /* BSD License */
2
3 /* Redistribution and use in source and binary forms, with or */
4 /* without modification, are permitted provided that the following */
5 /* conditions are met: */
6
7
8 /* Redistributions of source code must retain the above */
9 /* copyright notice, this list of conditions and the following */
10 /* disclaimer. */
11
12 /* Redistributions in binary form must reproduce the above */
13 /* copyright notice, this list of conditions and the following */
14 /* disclaimer in the documentation and/or other materials */
15 /* provided with the distribution. */
16
17
18 /* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY */
19 /* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, */
20 /* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A */
21 /* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR */
22 /* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
23 /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
24 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
25 /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND */
26 /* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT */
27 /* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING */
28 /* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF */
29 /* THE POSSIBILITY OF SUCH DAMAGE. */
30 #define _getsched_c_ 1
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <sched.h>
34 #include <errno.h>
35 #include <sys/types.h>
36 #ifdef HAVE_LIMITS_H
37 #include <limits.h>
38 #else
39 #define _POSIX_PATH_MAX 255
40 #endif
41 #include <string.h>
42 #include "util.h"
43 #include "config.h"
44 char progname[_POSIX_PATH_MAX];
45
46 void
print_usage()47 print_usage ()
48 {
49 fprintf (stderr, "Usage : %s [-h] pid [pid, ...]\n\
50 Gets the scheduler and priority used for processes identified with the pids.\n\
51 Options: -h print help (this text).\n\
52 pid - which pid to reschedule.\n", progname);
53
54 }
55
56 int
main(int argc,char * argv[])57 main (int argc, char *argv[])
58 {
59 pid_t thepid;
60 int ret;
61 struct sched_param oldpri;
62 int oldsched;
63
64
65 strcpy (progname, argv[0]);
66 if (argc < 2)
67 {
68 print_usage ();
69 return EXIT_FAILURE;
70 }
71 if (!strcmp ("-h", argv[1]))
72 {
73 print_usage ();
74 return EXIT_FAILURE;
75 }
76
77 while (--argc > 0 && (*++argv)[0]){
78 thepid = (pid_t) atoi (argv[0]);
79 if (thepid < 0)
80 {
81 fprintf(stderr,"Failed: pid cannot be negative.\n");
82 print_usage ();
83 return EXIT_FAILURE;
84 }
85
86 ret = oldsched = sched_getscheduler (thepid);
87 if (ret < 0)
88 {
89 perror ("Failed ");
90 return EXIT_FAILURE;
91 }
92 ret = sched_getparam (thepid, &oldpri);
93 if (ret < 0)
94 {
95 perror ("Failed ");
96 return EXIT_FAILURE;
97 }
98
99 print_sched (thepid, oldsched, &oldpri);
100
101 }
102 return EXIT_SUCCESS;
103
104 }
105