6

The mutex_lock_interruptible() function in the linux kernel basically tries to lock a mutex and will continue waiting until a task is interrupted. Well how do I actually interrupt a task?

Caleb Merchant
  • 289
  • 1
  • 5
  • 16

1 Answers1

8

Suffix _interruptible in Linux kernel means that waiting by the function will be interrupted if thread(process) receives the signal.

It can be signal sent by kill() user-space function, or signals generated by specific functions when condition met, e.g. by the timer (create_timer() when time is expired, or by asinchronous IO when pending operation has been completed.

Note, that uninterruptible wait cannot be interrupted even by SIGKILL, that is process cannot be finished until such wait ends.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • I have a kernel thread waiting for a mutex and I want it to stop waiting and return an error code, how can I do that? Is send_sig() the way to do it or is there a better way? – Caleb Merchant Jul 11 '16 at 11:28
  • 1
    Yes, you may use `send_sig()` for send signal within the kernel. – Tsyvarev Jul 11 '16 at 11:30