[SPARK-21093][R] Terminate R's worker processes in the parent of R's daemon to prevent a leak
[SPARK-21093][R] Terminate R's worker processes in the parent of R's daemon to prevent a leak

## What changes were proposed in this pull request?

`mcfork` in R looks opening a pipe ahead but the existing logic does not properly close it when it is executed hot. This leads to the failure of more forking due to the limit for number of files open.

This hot execution looks particularly for `gapply`/`gapplyCollect`. For unknown reason, this happens more easily in CentOS and could be reproduced in Mac too.

All the details are described in https://issues.apache.org/jira/browse/SPARK-21093

This PR proposes simply to terminate R's worker processes in the parent of R's daemon to prevent a leak.

## How was this patch tested?

I ran the codes below on both CentOS and Mac with that configuration disabled/enabled.

```r
df <- createDataFrame(list(list(1L, 1, "1", 0.1)), c("a", "b", "c", "d"))
collect(gapply(df, "a", function(key, x) { x }, schema(df)))
collect(gapply(df, "a", function(key, x) { x }, schema(df)))
...  # 30 times
```

Also, now it passes R tests on CentOS as below:

```
SparkSQL functions: Spark package found in SPARK_HOME: .../spark
..............................................................................................................................................................
..............................................................................................................................................................
..............................................................................................................................................................
..............................................................................................................................................................
..............................................................................................................................................................
....................................................................................................................................
```

Author: hyukjinkwon <gurwls223@gmail.com>

Closes #18320 from HyukjinKwon/SPARK-21093.

ptkool/spark,ptkool/spark,tengpeng/spark,BryanCutler/spark,jiangxb1987/spark,sureshthalamati/spark,rekhajoshm/spark,eyalfa/spark,rednaxelafx/apache-spark,gengliangwang/spark,kiszk/spark,ericvandenbergfb/spark,rednaxelafx/apache-spark,mdespriee/spark,WeichenXu123/spark,WindCanDie/spark,sureshthalamati/spark,janewangfb/spark,actuaryzhang/spark,tejasapatil/spark,hvanhovell/spark,WeichenXu123/spark,wzhfy/spark,HyukjinKwon/spark,1haodian/spark,witgo/spark,UndeadBaneGitHub/spark,techaddict/spark,sureshthalamati/spark,stanzhai/spark,mahak/spark,bdrillard/spark,eyalfa/spark,byakuinss/spark,gengliangwang/spark,ajaysaini725/spark,michalsenkyr/spark,xuanyuanking/spark,xflin/spark,esi-mineset/spark,xuanyuanking/spark,facaiy/spark,ueshin/apache-spark,michalsenkyr/spark,maropu/spark,vinodkc/spark,debugger87/spark,hhbyyh/spark,dbtsai/spark,rikima/spark,zuotingbing/spark,aosagie/spark,stanzhai/spark,shuangshuangwang/spark,rikima/spark,esi-mineset/spark,eyalfa/spark,brad-kaiser/spark,nlalevee/spark,tengpeng/spark,someorz/spark,yanboliang/spark,michalsenkyr/spark,kiszk/spark,spark-test/spark,mike0sv/spark,cloud-fan/spark,witgo/spark,aokolnychyi/spark,wzhfy/spark,UndeadBaneGitHub/spark,LantaoJin/spark,jiangxb1987/spark,shaneknapp/spark,pgandhi999/spark,HyukjinKwon/spark,UndeadBaneGitHub/spark,xuanyuanking/spark,zzcclp/spark,bdrillard/spark,adrian-ionescu/apache-spark,bravo-zhang/spark,janewangfb/spark,zero323/spark,ConeyLiu/spark,hvanhovell/spark,narahari92/spark,esi-mineset/spark,UndeadBaneGitHub/spark,rezasafi/spark,cin/spark,byakuinss/spark,wzhfy/spark,witgo/spark,BryanCutler/spark,Aegeaner/spark,xuanyuanking/spark,shuangshuangwang/spark,rekhajoshm/spark,icexelloss/spark,narahari92/spark,szhem/spark,shuangshuangwang/spark,saltstar/spark,ConeyLiu/spark,lvdongr/spark,gengliangwang/spark,joseph-torres/spark,kevinyu98/spark,hhbyyh/spark,alunarbeach/spark,milliman/spark,sureshthalamati/spark,nchammas/spark,mahak/spark,Aegeaner/spark,brad-kaiser/spark,cin/spark,taroplus/spark,someorz/spark,LantaoJin/spark,milliman/spark,cloud-fan/spark,Aegeaner/spark,ericvandenbergfb/spark,wangmiao1981/spark,caneGuy/spark,ioana-delaney/spark,actuaryzhang/spark,ptkool/spark,debugger87/spark,kevinyu98/spark,WeichenXu123/spark,icexelloss/spark,xuanyuanking/spark,szhem/spark,nchammas/spark,darionyaphet/spark,byakuinss/spark,aokolnychyi/spark,ConeyLiu/spark,shaneknapp/spark,dbtsai/spark,SHASHANKB/spark,minixalpha/spark,WindCanDie/spark,facaiy/spark,ddna1021/spark,zhouyejoe/spark,ueshin/apache-spark,ioana-delaney/spark,narahari92/spark,minixalpha/spark,gengliangwang/spark,rekhajoshm/spark,techaddict/spark,mahak/spark,ueshin/apache-spark,hhbyyh/spark,zuotingbing/spark,ptkool/spark,darionyaphet/spark,ahnqirage/spark,cin/spark,ahnqirage/spark,narahari92/spark,akopich/spark,holdenk/spark,nchammas/spark,skonto/spark,shaneknapp/spark,zhouyejoe/spark,ajaysaini725/spark,pgandhi999/spark,JoshRosen/spark,shaneknapp/spark,nilsgrabbert/spark,janewangfb/spark,spark-test/spark,nilsgrabbert/spark,highfei2011/spark,gengliangwang/spark,byakuinss/spark,joseph-torres/spark,nilsgrabbert/spark,zzcclp/spark,eyalfa/spark,witgo/spark,ron8hu/spark,shaneknapp/spark,bravo-zhang/spark,wangmiao1981/spark,guoxiaolongzte/spark,icexelloss/spark,markhamstra/spark,wangyum/spark,chuckchen/spark,adrian-ionescu/apache-spark,adrian-ionescu/apache-spark,UndeadBaneGitHub/spark,sahilTakiar/spark,kiszk/spark,shubhamchopra/spark,srowen/spark,nchammas/spark,jiangxb1987/spark,byakuinss/spark,michalsenkyr/spark,poffuomo/spark,guoxiaolongzte/spark,LantaoJin/spark,facaiy/spark,taroplus/spark,kevinyu98/spark,zhouyejoe/spark,rezasafi/spark,akopich/spark,aokolnychyi/spark,kevinyu98/spark,taroplus/spark,ueshin/apache-spark,zuotingbing/spark,jiangxb1987/spark,brad-kaiser/spark,lvdongr/spark,cin/spark,BryanCutler/spark,zhouyejoe/spark,apache/spark,rednaxelafx/apache-spark,skonto/spark,spark-test/spark,mahak/spark,JoshRosen/spark,rikima/spark,ajaysaini725/spark,shuangshuangwang/spark,byakuinss/spark,icexelloss/spark,darionyaphet/spark,dongjoon-hyun/spark,debugger87/spark,highfei2011/spark,vinodkc/spark,holdenk/spark,adrian-ionescu/apache-spark,ioana-delaney/spark,ahnqirage/spark,ioana-delaney/spark,jkbradley/spark,lvdongr/spark,tejasapatil/spark,cloud-fan/spark,aokolnychyi/spark,shubhamchopra/spark,pgandhi999/spark,bravo-zhang/spark,poffuomo/spark,shubhamchopra/spark,markhamstra/spark,maropu/spark,nchammas/spark,lxsmnv/spark,facaiy/spark,rekhajoshm/spark,rednaxelafx/apache-spark,spark-test/spark,dbtsai/spark,joseph-torres/spark,JoshRosen/spark,techaddict/spark,chuckchen/spark,bravo-zhang/spark,hvanhovell/spark,nlalevee/spark,caneGuy/spark,darionyaphet/spark,rezasafi/spark,wangyum/spark,WeichenXu123/spark,adrian-ionescu/apache-spark,srowen/spark,yanboliang/spark,aosagie/spark,rikima/spark,WindCanDie/spark,JoshRosen/spark,shubhamchopra/spark,highfei2011/spark,jkbradley/spark,skonto/spark,lxsmnv/spark,witgo/spark,cloud-fan/spark,poffuomo/spark,taroplus/spark,debugger87/spark,mdespriee/spark,chuckchen/spark,minixalpha/spark,ConeyLiu/spark,1haodian/spark,mahak/spark,highfei2011/spark,holdenk/spark,xflin/spark,ConeyLiu/spark,lxsmnv/spark,ron8hu/spark,wangmiao1981/spark,brad-kaiser/spark,ioana-delaney/spark,ericvandenbergfb/spark,maropu/spark,taroplus/spark,yanboliang/spark,WindCanDie/spark,lxsmnv/spark,zzcclp/spark,holdenk/spark,nilsgrabbert/spark,dongjoon-hyun/spark,nilsgrabbert/spark,techaddict/spark,stanzhai/spark,xuanyuanking/spark,nlalevee/spark,rezasafi/spark,someorz/spark,michalsenkyr/spark,alunarbeach/spark,caneGuy/spark,apache/spark,mdespriee/spark,wzhfy/spark,nilsgrabbert/spark,ddna1021/spark,zuotingbing/spark,shubhamchopra/spark,lxsmnv/spark,someorz/spark,minixalpha/spark,SHASHANKB/spark,rekhajoshm/spark,techaddict/spark,sureshthalamati/spark,pgandhi999/spark,ajaysaini725/spark,tengpeng/spark,hhbyyh/spark,ptkool/spark,sahilTakiar/spark,debugger87/spark,dongjoon-hyun/spark,JoshRosen/spark,rezasafi/spark,zhouyejoe/spark,guoxiaolongzte/spark,brad-kaiser/spark,hvanhovell/spark,wzhfy/spark,tengpeng/spark,skonto/spark,chuckchen/spark,hhbyyh/spark,WindCanDie/spark,ddna1021/spark,srowen/spark,narahari92/spark,srowen/spark,alunarbeach/spark,mdespriee/spark,wangmiao1981/spark,shuangshuangwang/spark,vinodkc/spark,aokolnychyi/spark,akopich/spark,dbtsai/spark,SHASHANKB/spark,brad-kaiser/spark,zuotingbing/spark,kevinyu98/spark,narahari92/spark,kiszk/spark,mahak/spark,zero323/spark,szhem/spark,aosagie/spark,zero323/spark,WeichenXu123/spark,nchammas/spark,wangyum/spark,dbtsai/spark,lvdongr/spark,darionyaphet/spark,someorz/spark,rikima/spark,joseph-torres/spark,shuangshuangwang/spark,kevinyu98/spark,srowen/spark,aray/spark,xflin/spark,mdespriee/spark,aosagie/spark,spark-test/spark,milliman/spark,hvanhovell/spark,holdenk/spark,poffuomo/spark,bdrillard/spark,michalsenkyr/spark,bdrillard/spark,WindCanDie/spark,LantaoJin/spark,mdespriee/spark,1haodian/spark,markhamstra/spark,markhamstra/spark,caneGuy/spark,SHASHANKB/spark,bdrillard/spark,rezasafi/spark,1haodian/spark,akopich/spark,LantaoJin/spark,lxsmnv/spark,zero323/spark,aosagie/spark,poffuomo/spark,ahnqirage/spark,mahak/spark,goldmedal/spark,nlalevee/spark,saltstar/spark,aray/spark,Aegeaner/spark,goldmedal/spark,ConeyLiu/spark,dongjoon-hyun/spark,tengpeng/spark,shuangshuangwang/spark,maropu/spark,stanzhai/spark,zzcclp/spark,caneGuy/spark,nlalevee/spark,apache/spark,pgandhi999/spark,esi-mineset/spark,BryanCutler/spark,apache/spark,sahilTakiar/spark,aray/spark,gengliangwang/spark,chuckchen/spark,spark-test/spark,aokolnychyi/spark,saltstar/spark,kiszk/spark,techaddict/spark,sahilTakiar/spark,JoshRosen/spark,bravo-zhang/spark,janewangfb/spark,tejasapatil/spark,lxsmnv/spark,jiangxb1987/spark,Aegeaner/spark,esi-mineset/spark,SHASHANKB/spark,techaddict/spark,cin/spark,maropu/spark,mike0sv/spark,janewangfb/spark,witgo/spark,wzhfy/spark,wangmiao1981/spark,ddna1021/spark,HyukjinKwon/spark,vinodkc/spark,xflin/spark,cloud-fan/spark,Aegeaner/spark,ddna1021/spark,zhouyejoe/spark,rezasafi/spark,xflin/spark,mike0sv/spark,taroplus/spark,ahnqirage/spark,ajaysaini725/spark,wangyum/spark,stanzhai/spark,taroplus/spark,BryanCutler/spark,zzcclp/spark,darionyaphet/spark,minixalpha/spark,nlalevee/spark,narahari92/spark,alunarbeach/spark,wangyum/spark,pgandhi999/spark,milliman/spark,szhem/spark,milliman/spark,someorz/spark,alunarbeach/spark,ddna1021/spark,dongjoon-hyun/spark,mike0sv/spark,HyukjinKwon/spark,janewangfb/spark,joseph-torres/spark,ericvandenbergfb/spark,pgandhi999/spark,sureshthalamati/spark,matthewfranglen/spark,szhem/spark,LantaoJin/spark,aray/spark,facaiy/spark,byakuinss/spark,holdenk/spark,markhamstra/spark,holdenk/spark,UndeadBaneGitHub/spark,zzcclp/spark,brad-kaiser/spark,ueshin/apache-spark,vinodkc/spark,bravo-zhang/spark,esi-mineset/spark,maropu/spark,WeichenXu123/spark,hvanhovell/spark,BryanCutler/spark,ericvandenbergfb/spark,saltstar/spark,yanboliang/spark,shaneknapp/spark,guoxiaolongzte/spark,eyalfa/spark,actuaryzhang/spark,akopich/spark,ericvandenbergfb/spark,someorz/spark,nchammas/spark,yanboliang/spark,mdespriee/spark,jiangxb1987/spark,eyalfa/spark,jkbradley/spark,jkbradley/spark,sahilTakiar/spark,poffuomo/spark,xuanyuanking/spark,eyalfa/spark,highfei2011/spark,srowen/spark,UndeadBaneGitHub/spark,bravo-zhang/spark,saltstar/spark,apache/spark,nilsgrabbert/spark,ioana-delaney/spark,milliman/spark,xflin/spark,chuckchen/spark,ron8hu/spark,jiangxb1987/spark,goldmedal/spark,zzcclp/spark,WindCanDie/spark,janewangfb/spark,lvdongr/spark,tejasapatil/spark,tejasapatil/spark,ron8hu/spark,michalsenkyr/spark,rikima/spark,shubhamchopra/spark,poffuomo/spark,mike0sv/spark,bdrillard/spark,apache/spark,Aegeaner/spark,aray/spark,ptkool/spark,esi-mineset/spark,1haodian/spark,ConeyLiu/spark,HyukjinKwon/spark,goldmedal/spark,stanzhai/spark,HyukjinKwon/spark,zuotingbing/spark,ron8hu/spark,rednaxelafx/apache-spark,xflin/spark,BryanCutler/spark,sahilTakiar/spark,zuotingbing/spark,SHASHANKB/spark,mike0sv/spark,caneGuy/spark,zero323/spark,guoxiaolongzte/spark,WeichenXu123/spark,rednaxelafx/apache-spark,actuaryzhang/spark,1haodian/spark,guoxiaolongzte/spark,ueshin/apache-spark,debugger87/spark,icexelloss/spark,tengpeng/spark,rekhajoshm/spark,zero323/spark,ueshin/apache-spark,kiszk/spark,saltstar/spark,wangyum/spark,adrian-ionescu/apache-spark,hvanhovell/spark,sureshthalamati/spark,mike0sv/spark,ron8hu/spark,milliman/spark,szhem/spark,minixalpha/spark,wzhfy/spark,lvdongr/spark,HyukjinKwon/spark,aray/spark,cloud-fan/spark,skonto/spark,facaiy/spark,goldmedal/spark,ajaysaini725/spark,vinodkc/spark,skonto/spark,icexelloss/spark,1haodian/spark,zero323/spark,skonto/spark,cloud-fan/spark,jkbradley/spark,wangmiao1981/spark,gengliangwang/spark,minixalpha/spark,dongjoon-hyun/spark,cin/spark,dbtsai/spark,ahnqirage/spark,markhamstra/spark,apache/spark,ericvandenbergfb/spark,rekhajoshm/spark,yanboliang/spark,nlalevee/spark,hhbyyh/spark,szhem/spark,akopich/spark,ajaysaini725/spark,chuckchen/spark,facaiy/spark,ptkool/spark,joseph-torres/spark,ddna1021/spark,guoxiaolongzte/spark,ioana-delaney/spark,bdrillard/spark,debugger87/spark,wangyum/spark,yanboliang/spark,vinodkc/spark,wangmiao1981/spark,caneGuy/spark,spark-test/spark,highfei2011/spark,saltstar/spark,icexelloss/spark,joseph-torres/spark,zhouyejoe/spark,witgo/spark,SHASHANKB/spark,dongjoon-hyun/spark,actuaryzhang/spark,rikima/spark,tejasapatil/spark,cin/spark,shubhamchopra/spark,goldmedal/spark,sahilTakiar/spark,goldmedal/spark,tengpeng/spark,aray/spark,jkbradley/spark,ahnqirage/spark,srowen/spark,aosagie/spark,highfei2011/spark,actuaryzhang/spark,maropu/spark,actuaryzhang/spark,darionyaphet/spark,stanzhai/spark,akopich/spark,aosagie/spark,markhamstra/spark,LantaoJin/spark,hhbyyh/spark,dbtsai/spark,shaneknapp/spark,kevinyu98/spark,tejasapatil/spark,aokolnychyi/spark,rednaxelafx/apache-spark,alunarbeach/spark,alunarbeach/spark,kiszk/spark,ron8hu/spark,JoshRosen/spark,jkbradley/spark,adrian-ionescu/apache-spark,lvdongr/spark