سلام. می خوام در ادامه ی برنامه ی زیر (که در آن اگر کاربر عدد 1 را وارد کند زمان فعلی سیتم نشان داده می شود ) کدی اضافه کنم که اگر عدد 2 را زد ، مدت زمانی که سی پی یو برای همه پردازه ها صرف کرده (هم مود کاربر و هم مود کرنل) را نشان دهد.
و هم چنین اگر عدد 3 را زد، تعداد صفحات faults شده ای را که سی پی یو از زمان بوت تا حالا handle کرده را برگرداند.
int procfile_read(char *buffer,char **buffer_location,off_t offset, int buffer_length, int *eof, void *data)
{
int ret;
int i=0;
// The global variable jiffies holds the number of ticks that have occurred since the system booted.
// because there are HZ timer interrupts in a second, there are HZ jiffies in a second. The system uptime is therefore jiffies/HZ seconds.
int y =jiffies/HZ;//uptime
__kernel_time_t nn;//time
struct timespec tss;//time
tss=current_kernel_time();//time
nn=tss.tv_sec;//time
nn=nn+16200;//time
int ss=nn % 60; nn= nn/60;//time
int mm=nn % 60; nn= nn /60;//time
int hh=nn % 24; nn= nn/24;//time
printk(KERN_EMERG "procfile_read (/proc/OsLabProject/%s) called\n", procfs_name);
if (offset > 0)
{
/* we have finished to read, return 0 */
ret = 0;
}
else
{
if (param[0]=='1')
{
ret=sprintf(buffer,"Current system time: %d:%d:%d\n", hh,mm,ss);
printk(KERN_INFO "Current system time: %d:%d:%d\n", hh,mm,ss);
}