问题
I'm writing something on the linux scheduler and I need to know which process was running before my interrupt came in.. is the current structure available? If I do current->pid while in the interrupt handler, do I get the pid of the process I interrupted?
回答1:
You can, current->pid
exists and is the process that was interrupted (may be the idle thread, or any).
If you're writing inside the Linux scheduler, you should be very careful. current
is changed by the scheduler as it chooses a new process to run, so its value depends on when exactly you read it.
回答2:
I wouldn't expect current to be valid outside process context. If you're working on scheduler maybe you can get hold of where it stores pointer to running task, e.g. struct cfs_rq.
来源:https://stackoverflow.com/questions/10570836/get-current-pid-while-in-interrupt