buratino
buratino

Reputation: 1518

task_pid_nr(current) returns a pid that doesn't appear in the output of ps

Within the linux kernel (4.5.5), I have added a printk() to mm/filemap.c.

The code that I have added is inside of __generic_file_write_iter():

if(io_tracing_on) {
        ssize_t write_size = iov_length(from->iov, from->nr_segs);
        printk(KERN_INFO "write size=%zu, pid=%d, inode=%lu\n", write_size, task_pid_nr(current), inode->i_ino);
}

When io_tracing_on evaluates to true, I get a continuous stream of output (discussed in a different question) as follows:

Jun 27 15:00:41 malka kernel: [  463.424155] write size=168, pid=715, inode=7864653
Jun 27 15:00:41 malka kernel: [  463.428064] write size=168, pid=715, inode=7864354

During this continuous stream of output, I have tried to map the pid (715) to my the output of ps -ef, to no avail -- the pid does not exist in the process list. Is there a way for me to determine what process task_pid_nr(current) is referring to?

Upvotes: 0

Views: 3213

Answers (1)

Alex Hoppus
Alex Hoppus

Reputation: 3935

The pid in kernel have a little bit different meaning, you should use tgid to match pid from userspace perspective

Upvotes: 1

Related Questions