Which signal does the oom killer send to kill the process?

219 篇文章 2 订阅

 

Which signal does the oom killer send to kill the process?

 SOLUTION 已验证 - 已更新 2015年十二月22日22:06 - 

English 

环境

  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7

问题

  • Which signal does the oom killer send to kill the process?
  • Which signal (SIGTERMSIGKILL, other?) does the oom killer use to kill processes?

决议

Although the oom killer source code mm/oom_kill.c has many changes and will continue to have in future for optimise, Improvisation purposes. But the signal which is sent to the process in an event of a oom is still the SIGKILL signal. Please find the source code snippet from RHEL 6.6.

Raw

static int oom_kill_task(struct task_struct *p)
{
        struct task_struct *q;
        struct mm_struct *mm;

        p = find_lock_task_mm(p);
        if (!p)
                return 1;

        if (sysctl_would_have_oomkilled == 1) {
                printk(KERN_ERR "Would have killed process %d (%s). But continuing instead.\n",
                                task_pid_nr(p), p->comm);
                task_unlock(p);
                return 0;
        }

        /* mm cannot be safely dereferenced after task_unlock(p) */
        mm = p->mm;

        pr_err("Killed process %d, UID %d, (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
                task_pid_nr(p), task_uid(p), p->comm, K(p->mm->total_vm),
                K(get_mm_counter(p->mm, anon_rss)),
                K(get_mm_counter(p->mm, file_rss)));
        task_unlock(p);

        /*
         * Kill all processes sharing p->mm in other thread groups, if any.
         * They don't get access to memory reserves or a higher scheduler
         * priority, though, to avoid depletion of all memory or task
         * starvation.  This prevents mm->mmap_sem livelock when an oom killed
         * task cannot exit because it requires the semaphore and its contended
         * by another thread trying to allocate memory itself.  That thread will
         * now get access to memory reserves since it has a pending fatal
         * signal.
         */
        for_each_process(q)
                if (q->mm == mm && !same_thread_group(q, p)) {
                        task_lock(q);   /* Protect ->comm from prctl() */
                        pr_err("Kill process %d (%s) sharing same memory\n",
                                task_pid_nr(q), q->comm);
                        task_unlock(q);
                        force_sig(SIGKILL, q);
                }

        set_tsk_thread_flag(p, TIF_MEMDIE);
        force_sig(SIGKILL, p);

        return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值