Omit Foreground/Background scheduling on non-Android. Update ps.c
to work the same way.
diff --git a/ps.c b/ps.c
index c7dea95..e7f7003 100644
--- a/ps.c
+++ b/ps.c
@@ -11,7 +11,8 @@
#include <pwd.h>
-#ifdef HAS_SCHED_POLICY
+#ifndef NO_ANDROID_HEADERS
+#define HAS_SCHED_POLICY
#include <cutils/sched_policy.h>
#endif
diff --git a/top.c b/top.c
index daade6d..0f7615f 100644
--- a/top.c
+++ b/top.c
@@ -39,7 +39,10 @@
#include <sys/types.h>
#include <unistd.h>
+#ifndef NO_ANDROID_HEADERS
+#define HAS_SCHED_POLICY
#include <cutils/sched_policy.h>
+#endif
struct cpu_info {
long unsigned utime, ntime, stime, itime;
@@ -66,7 +69,9 @@
long vss;
long rss;
int num_threads;
+#ifdef HAS_SCHED_POLICY
char policy[32];
+#endif
};
struct proc_list {
@@ -377,6 +382,7 @@
}
static void read_policy(int pid, struct proc_info *proc) {
+#ifdef HAS_SCHED_POLICY
SchedPolicy p;
if (get_sched_policy(pid, &p) < 0)
strcpy(proc->policy, "unk");
@@ -388,6 +394,7 @@
else
strcpy(proc->policy, "er");
}
+#endif
}
static int read_status(char *filename, struct proc_info *proc) {
@@ -477,12 +484,27 @@
snprintf(group_buf, 20, "%d", proc->gid);
group_str = group_buf;
}
+#ifdef HAS_SCHED_POLICY
if (!threads)
printf("%5d %3ld%% %c %5d %6ldK %6ldK %3s %-8.8s %s\n", proc->pid, proc->delta_time * 100 / total_delta_time, proc->state, proc->num_threads,
proc->vss / 1024, proc->rss * getpagesize() / 1024, proc->policy, user_str, proc->name[0] != 0 ? proc->name : proc->tname);
else
printf("%5d %5d %3ld%% %c %6ldK %6ldK %3s %-8.8s %-15s %s\n", proc->pid, proc->tid, proc->delta_time * 100 / total_delta_time, proc->state,
proc->vss / 1024, proc->rss * getpagesize() / 1024, proc->policy, user_str, proc->tname, proc->name);
+#else
+ if (!threads)
+ printf("%5d %3ld%% %c %5d %6ldK %6ldK %-8.8s %s\n",
+ proc->pid, proc->delta_time * 100 / total_delta_time,
+ proc->state, proc->num_threads,
+ proc->vss / 1024, proc->rss * getpagesize() / 1024,
+ user_str, proc->name[0] != 0 ? proc->name : proc->tname);
+ else
+ printf("%5d %5d %3ld%% %c %6ldK %6ldK %-8.8s %-15s %s\n",
+ proc->pid, proc->tid,
+ proc->delta_time * 100 / total_delta_time, proc->state,
+ proc->vss / 1024, proc->rss * getpagesize() / 1024,
+ user_str, proc->tname, proc->name);
+#endif
}
}