c - Build agains newer linux headers than libc is built using -


i want write program using new sched_deadline scheduling policy available since linux 3.14.

i start out simple program trying use sched_setattr function.

#include <sched.h>  int main(void) {     // struct sched_attr attr;     // attr.size = sizeof(struct sched_attr);     // attr.sched_policy = sched_deadline;     sched_setattr(0, (void*)0, 0);      return 0; } 

however when compiling following error:

$gcc dead.c  dead.c: in function ‘main’: dead.c:8:2: warning: implicit declaration of function ‘sched_setattr’ [-wimplicit-function-declaration]   sched_setattr(0, (void*)0, 0);   ^~~~~~~~~~~~~ /tmp/ccgxwxze.o: in function `main': dead.c:(.text+0x19): undefined reference `sched_setattr' collect2: error: ld returned 1 exit status 

my system running ubuntu 16.10 yakkety, kernel 4.8.0-59-generic. sched.h file included found in /usr/include/sched.h , provided package libc6-dev. headerfile not contain function sched_setattr , friends trying use.

however kernel (and kernel headers) have installed comes sched.h header file containing definitions need. located @ /usr/src/linux-headers-4.8.0-58/include/linux/sched.h, on system.

so naively think lets build against newer linux headers instead of libc6-dev provided headers. program run on or newer kernels, fine.

i modify first line be: #include <linux/sched.h> , execute:

gcc -i/usr/src/linux-headers-$(uname -r)/include -i/usr/src/linux-headers-$(unam -r)/arch/x86/include dead.c 

now getting page after page of errors , warning. not seem way go.

what correct way build userspace program against newer linux headers provided libc?

and subsequently how build program above?

sched_setattr() syscall , doesn't seem have one-to-one libc wrapper. wrapper yourself, this:

#define _gnu_source #include <stdio.h> #include <string.h> #include <stdint.h> #include <unistd.h> #include <linux/sched.h> #include <sys/syscall.h> #include <sys/types.h>  struct sched_attr {     uint32_t size;              /* size of structure */     uint32_t sched_policy;      /* policy (sched_*) */     uint64_t sched_flags;       /* flags */     int32_t sched_nice;         /* nice value (sched_other, sched_batch) */     uint32_t sched_priority;    /* static priority (sched_fifo, sched_rr) */     /* remaining fields sched_deadline */     uint64_t sched_runtime;     uint64_t sched_deadline;     uint64_t sched_period; };  static int sched_setattr (pid_t pid, const struct sched_attr *attr, unsigned int flags) {     return syscall (sys_sched_setattr, pid, attr, flags); }  int main (int argc, char *argv[]) {     struct sched_attr attr;     int res;      memset (&attr, 0, sizeof (struct sched_attr));     attr.size = sizeof (struct sched_attr);      res = sched_setattr (getpid (), &attr, 0);     if (res < 0) {         perror ("sched_setattr");         return 1;     }      return 0; } 

looking @ errors reported when trying include kernel header files required definition of struct sched_attr , reading comments found googling "kernel headers in user space", can't suggest trying include kernel header files this.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -