process infomation get within kernel

linux get process name from pid within kernel

  unsigned int pid = task_pid_nr(current);

 unsigned char * comm= current->comm;

printk(KERN_INFO “Simon:pid=%u,comm=%s\n,pid,comm);

How to get current process’s UID and EUID in Linux Kernel 4.2?

unsigned int uid = current_uid();

unsigned int euid = current_euid();

 unsigned int suid = current_suid();

unsigned int gid = current_gid();

Get time within kernel :

unsigned int get_kernel_time_sec()


        struct timeval ctv;


        return (unsigned int)ctv.tv_usec;

}// And then you can create a rand function based on time. 

unsigned int rand(unsigned int limit)


        unsigned int c_tv = get_kernel_time_sec();



                return c_tv;




                return c_tv%limit;



#include <linux/cred.h> // current_uid & current_euid

#include <linux/time.h> // current_kernel_time

#include <linux/types.h> //timespec

#include <linux/timer.h>

#include <linux/sched.h> // task_pid_nr    current->comm;


电子邮件地址不会被公开。 必填项已用*标注