get current->pid while in interrupt

99封情书 提交于 2019-12-21 03:15:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!