I'm assuming that you are creating a simple Linux character device, to be created in a location such as /dev/mydev. If this is the case then the following should give you a good example of how to do it. However, if you have a different meaning for open a device, then this won't be applicable.
Your char device file operations
struct file_operations mydev_fops = {
.open = mydev_open,
};
Your mydev_open()
static int mydev_open(struct inode *inode, struct file *filp)
{
pid_t pid;
int user_id;
/* This is the thread-ID, traditional PID is found in current->pgid */
pid = current->pid;
/* The current user-id (as of 2.6.29) */
user_id = current_uid();
}
For more information about what you can find out about the current process, then check out the header file include/linux/cred.h.