本文介绍了在中断时获得current-> pid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在linux调度程序上写一些东西,我需要知道在插入中断之前正在运行哪个进程..当前结构可用吗?如果我在中断处理程序中执行current-> pid,是否可以获得我中断的进程的pid?

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?

推荐答案

可以,current->pid存在并且是被中断的进程(可以是空闲线程,也可以是任何线程).

You can, current->pid exists and is the process that was interrupted (may be the idle thread, or any).

如果要在Linux调度程序中编写代码,则应格外小心. current由调度程序更改,因为它选择了要运行的新进程,因此其值取决于您确切地读取它的时间.

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.

这篇关于在中断时获得current-> pid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 18:08