2

I'm working on a kernel module and I'm trying to uniquely identify each one of the users trying to open() the module (can be either processes or threads).

What is the best way to identify them? Is there an ID I can get from a system call?

I wish to get all users in a list that specifies whether they're trying to open the module for read/write, and I need to know which one tried acting.

4

3 に答える 3

3

/dev/mydevなどの場所に作成される単純な Linux character deviceを作成していると仮定しています。その場合は、次の例を参考にしてください。ただし、open a deviceに別の意味がある場合、これは当てはまりません。

あなたのcharデバイスファイル操作

struct file_operations mydev_fops = {
    .open = mydev_open,
};

あなたの 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();
}

現在のプロセスに関する詳細については、ヘッダー ファイルinclude/linux/cred.h を参照してください。

于 2010-08-02T14:59:17.417 に答える
0

openメソッドが呼び出されると、currentそれをtask_struct呼び出しているタスク (~= スレッド) を指します。

ただし、これが正しいアプローチであることはめったにありません。

于 2010-05-25T00:45:18.650 に答える
0

要件に応じて、一意の意味を決定します。一意のタプルは、(pid) だけで構成できます。または、(tid、uid)、(filp)、または (inode) の場合もあります。

于 2010-11-22T03:34:56.307 に答える