I have a character driver that I've been modifying. In the kernel API "open" and "release" call I have the following code used to get the calling application's PID:

pid = pid_nr(task_pid(current));

It does match the application and so I've been using it to track the calls to the driver.

During testing I've used a test stub to "open" the device and wait. When I terminate the application with a CTRL-C the kernel API calls the "release" function. This time the PID is different. This is essentially being used to emulate the application terminating badly. Can anyone explain why the PID would be different under these circumstances and if there is a solution to this. I use the PID to track the current state of the character device when multiple applications are using the same resource.