您好,登錄后才能下訂單哦!
listener為何要進行fork兩次子進程,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
大致分為6個階段
1
客戶端向數據庫發起連接請求,listener負責響應接受;
2
Listener進程fork子進程1;
如果子進程1運行時間過長,則會導致listener長時間等待(期間不接受其他數據庫連接);如果子進程1異常則listener會hang;--這句話質疑著很多,我也只是從相關資料摘抄的,沒有試驗根據
Ps –ef | grep tnslsnr顯示的ppid!=1的進程便是
3
子進程1fork子進程2,然后前者退出;
此時listener等待接受子進程2的數據
4
子進程2執行系統調用exec oracle,變為oracle server process,其向listener發送自身元數據(比如pid)
5
Listener向server procees發送客戶端數據,然后寫入listener.log;
直到此刻listener任務完成,可以接著處理下一個連接
6
Server process與客戶端交互,完成后續工作
問題:
為何listener要創建fork兩次子進程,直接采用第一個子進程調用exec oracle不可以么?
以下是回復,個人受教很多
本帖最后由 Yong Huang 于 2013-6-28 08:48 編輯
It's always a good habit to give reference, unless you find all this out completely from your own test.
I've done such test a long time ago. What you described is basically correct. But this
“如果子進程1運行時間過長,則會導致listener長時間等待(期間不接受其他數據庫連接);如果子進程1異常則listener會hang”
is new to me. I'd like to know the source.
The reason why listener needs to fork twice is related to the requirement of a UNIX daemon. The best answer is here:
http://stackoverflow.com/questio ... n-creating-a-daemon
Basically, if it forked only once, the server (shadow) process would still have a parent i.e. the tnslsnr process instead of init (pid 1). Forking twice, after the first child exits, the second child will definitely become an orphan and then init becomes its parent.
You may ask why bother to make sure the server process is a daemon. I think the answer is just that Oracle wants to make sure the server process is independent of the listener, so if the listener dies, existing server processes continue to function because they're immune from signals that will be sent to the listener.
freas
發表于 2013-6-29 00:57:21 |只看該作者
Yong Huang 發表于 2013-6-28 22:46
|
Yong
> Oracle為什么會這么想,也就無從得知了
Didn't you already answer this question? "Oracle的想法比較悲觀,覺得父進程(listener)一定會異常". In case the listener crashes, the server process must be protected from crashing. Although I think it's possible to program the child to not receive any signal delivered to the parent (tnslsnr), it's safer to just fork one more time and let the first child exit.
I haven't checked 12c. But I think somebody says beginning with 12c, Oracle on UNIX/Linux adopts the thread model as on Windows. Hope somebody can check.
freas
1、Oracle采用doule fork主要你是為了預防子進程退出時,listener已經crash了,子進程成為僵死進程沒有解決策略。至于"in case the listener crashes, the server process must be protected from crashing",父進程crash,子進程仍然可以正常運行,只是子進程調用exit之后,會成為僵死進程。
2、“> Oracle為什么會這么想,也就無從得知了
Didn't you already answer this question? "Oracle的想法比較悲觀,覺得父進程(listener)一定會異常". ”我只是從技術層面猜測一下,而且,在上面的猜測里,double fork的方法作為一個server的網絡處理方式,在2013年7月27日看來,弊大于利。
3、我個人覺得這種double fork的方式更多的是從DBA的管理上來設計的。因為Oracle提供listener的start/stop/restart接口。如果沒有采用double fork方式,一旦listener stop了,所有的server process必然成為孤兒進程(此時,server process可能正在執行復雜的transaction,風險太大),而server process顯然不應該在“正式干活”的時候受到listener的運行狀態的影響,所以直接在一開始就把這個有風險的操作主動做了,掌握控制權。
關于listener為何要進行fork兩次子進程問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。