linux下c 多线程如何映射文件夹,c - 在Linux中使用多个线程进行信号处理
signal(7)描述了POSIX.1要求進程共享屬性中的所有線程,包括:
信號處理
POSIX.1還要求每個線程都有一些不同的屬性,包括:
信號掩碼(signal(7))
備用信號堆棧(signal(7))
Linux內核的signal(7)例程具有以下代碼塊 - 注釋非常有用:
/*
* Now find a thread we can wake up to take the signal off the queue.
*
* If the main thread wants the signal, it gets first crack.
* Probably the least surprising to the average bear.
*/
if (wants_signal(sig, p))
t = p;
else if (!group || thread_group_empty(p))
/*
* There is just one thread and it does not need to be woken.
* It will dequeue unblocked signals before it runs again.
*/
return;
else {
/*
* Otherwise try to find a suitable thread.
*/
t = signal->curr_target;
while (!wants_signal(sig, t)) {
t = next_thread(t);
if (t == signal->curr_target)
/*
* No thread needs to be woken.
* Any eligible threads will see
* the signal in the queue soon.
*/
return;
}
signal->curr_target = t;
}
/*
* Found a killable thread. If the signal will be fatal,
* then start taking the whole group down immediately.
*/
if (sig_fatal(p, sig) &&
!(signal->flags & SIGNAL_GROUP_EXIT) &&
!sigismember(&t->real_blocked, sig) &&
(sig == SIGKILL || !p->ptrace)) {
/*
* This signal will be fatal to the whole group.
*/
所以,你看到你負責傳遞信號的地方:
如果您的進程已將信號的處置設置為signal(7)或SIG_DFL,則會忽略所有線程的信號(或默認值 - kill,core或ignore)。
如果您的進程已將信號設置為特定處理程序例程,則可以通過使用signal(7)操縱特定線程信號掩碼來控制哪個線程將接收信號。您可以指定一個線程來管理它們,或者為每個信號創建一個線程, 或者這些選項的任何混合用于特定信號,或者您依賴于Linux內核當前將信號傳遞到主線程的默認行為。
但是,根據signal(7)手冊頁,某些信號是特殊的:
可以為整個過程生成(并因此待決)信號?? (例如,使用kill(2)發送時)或特定線程(例如,?? 某些信號,如SIGSEGV和SIGFPE,生成為?? 執行特定機器語言指令的結果是?? 線程定向,以及針對特定線程使用的信號??pthread_kill(3))。 可以將過程引導的信號傳遞給任何信號?? 其中一個當前沒有阻塞信號的線程。?? 如果多個線程的信號未被阻塞,那么?? 內核選擇一個任意線程來傳遞信號。
總結
以上是生活随笔為你收集整理的linux下c 多线程如何映射文件夹,c - 在Linux中使用多个线程进行信号处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux系统分配文件夹内存,详解Lin
- 下一篇: linux 其他常用命令