I'm using Linux, and I need to find the offset of a pointer member withing task_struct which is defined in sched.h as follows
Expand|Select|Wrap|Line Numbers
- struct task_struct {
- volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
- struct thread_info *thread_info;
- atomic_t usage;
- unsigned long flags; /* per process flags, defined below */
- unsigned long ptrace;
- int lock_depth; /* BKL lock depth */
- #if defined(CONFIG_SMP) && defined(__ARCH_WANT_UNLOCKED_CTXSW)
- int oncpu;
- #endif
- int prio, static_prio;
- struct list_head run_list;
- prio_array_t *array;
- .... /*ect*/
- ...
- #define next_task(p) list_entry((p)->tasks.next, struct task_struct, tasks)
- #define prev_task(p) list_entry((p)->tasks.prev , struct task_struct, tasks)
- #define for_each_process(p) \
- for (p = &init_task ; (p = next_task(p)) != &init_task ; )
Expand|Select|Wrap|Line Numbers
- #include <stddef.h>
- #include </usr/include/linux/sched.h>
- int
- main
- ()
- {
- int A;
- A = offsetof(struct task_struct, next_task);
- printf ("%d \n", A);
- }
However, ever since I've included the sched.h headerfile, I have been getting a neverending series of compliation errors from all the other h files included in sched.h
Am i making incorrect use of the headerfiles?
I am using gcc with a Bash shell.