是条件编译的问题吗?
typedef struct {
/* /proc/<PID>/stat */
pid_tpid; /* %d */
charcomm[FNAME_BUFLEN+1];/* %s */
charstate; /* %c */
charpad1[2]; /* %s */
pid_tppid; /* %d */
pid_tpgrp; /* %d */
pid_tsession; /* %d */
inttty_nr; /* %d */
inttpgid; /* %d */
charspace1[4]; /* boundary adjustment */
#if _EL6_
UINT32flags; /* %u */
#else
ULONGflags; /* %lu */
#endif
ULONGmin_flt; /* %lu */
ULONGcmin_flt; /* %lu */
ULONGmaj_flt; /* %lu */
ULONGcmaj_flt;/* %lu */
ULONGutime;/* %lu */
ULONGstime;/* %lu */
longcutime;/* %ld */
longcstime;/* %ld */
longpriority;/* %ld */
longnice;/* %ld */
intnum_threads;/* %d */
charspace2[4];/* boundary adjustment */
longit_real_value;/* %ld */
unsigned long long
start_time;/* %llu */
ULONGvsize;/* %lu */
longrss;/* %ld */
ULONGrlim;/* %lu */
ULONGstart_code;/* %lu */
ULONGend_code;/* %lu */
ULONGstart_stack;/* %lu */
ULONGkstkesp;/* %lu */
ULONGkstkeip;/* %lu */
ULONGsignal;/* %lu */
ULONGblocked;/* %lu */
ULONGsigignore;/* %lu */
ULONGsigcatch;/* %lu */
ULONGwchan;/* %lu */
ULONGreserve1;/* %lu */
ULONGreserve2;/* %lu */
intexit_signal;/* %d */
intprocessor;/* %d */
#if _EL6_
UINT32rt_priority;/* %u */
UINT32policy;/* %u */
#elif _EL5_
ULONGrt_priority;/* %lu */
ULONGpolicy;/* %lu */
#endif
unsigned long long
delayacct_blkio_ticks;/* %llu */
#if _EL6_
ULONGguest_time;/* %lu */
longcguest_time;/* %ld */
#endif
/* /proc/<PID>/status */
int32_tuid; /* %d */
/* /proc/<PID>/cmdline */
charargs[ARGS_BUFLEN+1];/* psargs buffer [81]*/
charpad2[3];
} PROC_ST;/* 32bit:256 bytes / 64bit:392 bytes */
以上是结构体的定义。
int main()
{
PROC_STlp_st;
charpathname[64], buf[512], cmd[32];
FILE*fp;
intres;
spf(pathname, "/proc/%s/stat", pidstr);
fp = fopen(pathname, "r");
res = sscanf(buf, PROC_FRM,
&lp_st.pid, /* %d *//* pid */
cmd, /* (%s) *//* fname */
&lp_st.state, /* %c */
&lp_st.ppid, /* %d *//* ppid */
&lp_st.pgrp, /* %d */
&lp_st.session, /* %d */
&lp_st.tty_nr, /* %d */
&lp_st.tpgid, /* %d */
&lp_st.flags, /* %lu */
&lp_st.min_flt, /* %lu */
&lp_st.cmin_flt, /* %lu */
&lp_st.maj_flt, /* %lu */
&lp_st.cmaj_flt, /* %lu */
&lp_st.utime, /* %lu */
&lp_st.stime, /* %lu */
&lp_st.cutime, /* %ld */
&lp_st.cstime, /* %ld */
&lp_st.priority, /* %ld */
&lp_st.nice, /* %ld */
&lp_st.num_threads, /* %d */
&lp_st.it_real_value, /* %ld */
&lp_st.start_time, /* %llu *//* start_time */
&lp_st.vsize, /* %lu */
&lp_st.rss, /* %ld */
&lp_st.rlim, /* %lu */
&lp_st.start_code, /* %lu */
&lp_st.end_code, /* %lu */
&lp_st.start_stack, /* %lu */
&lp_st.kstkesp, /* %lu */
&lp_st.kstkeip, /* %lu */
&lp_st.signal, /* %lu */
&lp_st.blocked, /* %lu */
&lp_st.sigignore, /* %lu */
&lp_st.sigcatch, /* %lu */
&lp_st.wchan, /* %lu */
&lp_st.reserve1, /* %lu */
&lp_st.reserve2, /* %lu */
&lp_st.exit_signal, /* %d */
&lp_st.processor, /* %d */
&lp_st.rt_priority, /* %lu */
#ifdef _EL6_
&lp_st.policy, /* %lu */
&lp_st.delayacct_blkio_ticks, /* %llu */
&lp_st.guest_time, /* %lu */
&lp_st.cguest_time); /* %ld */
#else
&lp_st.policy, /* %lu */
&lp_st.delayacct_blkio_ticks); /* %llu */
#endif
}
gcc -D_EL6_ de 时候老是报错说:
结构体PROC_ST中没有成元:
flags到cguest_time;
-D_EL5_没有问题;
求大神解答,是不是条件编译出了什么问题?
[解决办法]
#ifdef 吧,不是#if
[解决办法]
#if _EL6_的话得类似#define _EL6_ 1这样的情况才能进去吧
个人理解,欢迎指正
[解决办法]
-D_EL5_没有问题;把_EL6_和_EL5_对调一下测试测试.