当前位置: 技术问答>linux和unix
求助:父进程被kill掉以后,子进程在任务表中所占内存是怎样释放的?
来源: 互联网 发布时间:2016-05-01
本文导语: 哪位大虾能帮下忙?! linux中,通常父进程会等待子进程终止以后,释放子进程在任务数据结构中所占的内存以及任务数组中的指针项。但是,如果子进程还没终止,就kill掉了父进程。等子进程终止后,在任务表中...
哪位大虾能帮下忙?!
linux中,通常父进程会等待子进程终止以后,释放子进程在任务数据结构中所占的内存以及任务数组中的指针项。但是,如果子进程还没终止,就kill掉了父进程。等子进程终止后,在任务表中所占内存是如何释放的?
linux中,通常父进程会等待子进程终止以后,释放子进程在任务数据结构中所占的内存以及任务数组中的指针项。但是,如果子进程还没终止,就kill掉了父进程。等子进程终止后,在任务表中所占内存是如何释放的?
|
你的理解有误,子进程中的资源不是由创建它的父进程来释放的,而是由kernel来完成。
当一个子进程的父进程退出后,init进程就会成为该子进程的父进程,当该子进程退出是init进程会调用wait来
释放该子进程在进程表中占用的资源。
|
父进程被kill掉后,子进程就交给init进程来管理了
|
Unix环境高级编程说道
The final condition to consider is this: what happens when a process that has been inherited by init terminates? Does it become a zombie? The answer is "no," because init is written so that whenever one of its children terminates, init calls one of the wait functions to fetch the termination status. By doing this, init prevents the system from being clogged by zombies. When we say "one of init's children," we mean either a process that init generates directly (such as getty, which we describe in Section 9.2) or a process whose parent has terminated and has been subsequently inherited by init
|
我们学的《unix/linux高级编程》中,说如果父进程在子进程中如果提前退出的话,那么子进程
也不会变成“孤儿”,他们还受到“国家”保护,就是init(1)进程!
也不会变成“孤儿”,他们还受到“国家”保护,就是init(1)进程!
|
父亲死后, 儿子就是孤儿, 被init领养, 一切都由init负责!