每个子shell都有自己的命名空间吗?

时间:2018-06-01 07:05:26

标签: linux shell

我想知道不同的子shell是否具有不同的命名空间,以便它们的pid不会相互影响。这是我的测试程序。据我所知,PID的最大值是32678.我在子shell'test'中使用了所有这些值,因此pid必须在子shell'test2'中崩溃。在我运行我的测试程序之前,我猜测程序会抛出'PID不是这个shell的孩子'的例外。但事实上,一切顺利。当我检查日志文件时,子shell测试和子shell测试2确实有一些相同的pid。那么,不同的子shell有不同的命名空间?或者我的测试程序错了?

#!/bin/bash
test2(){
    sleep 1000
    exit 1
}

test(){
    i=0
    max=32767
    arr=
    while [ $i -lt $max ]
    do
        echo $i
        sleep 1 &
        arr[$i]="$! $i"
        let i++
    done
    #phase 1
    echo "Test have already used 32768 PID. " >> ./log
    #wait for test2 finished
    sleep 20
    for temp in "${arr[@]}" ; do
        test=(${temp})
        pid=${test[0]}  
        name=${test[1]} 

        echo "pid  :$pid" >> ./log
        echo "name : $name" >> ./log
        if [[ ! -z ${pid} ]] ; then
            wait ${pid} 2>&1 >>./waitlog
            result=$?
            if [[ ${result} -eq 0 ]] 
            then
                echo "Result is ok. PID$pid finished successfully " 
            else
                echo "Wrong!!!!!!!!!!!!!!!!!!!!!!!!!! PID$pid met some 
                      problems. Result is $result ." >> ./log
            fi
        fi
        echo 
    done
    ps -f --forest >> ./process
}

test &
#wait for phase 1 finished
sleep 60
ii=0
max2=10000
while [ $ii -lt $max2 ]
do
    test2 &
    echo "PID :$!  test2 is working... " >> ./log
    let ii++
done
echo "Test2 created 2000 process after test userd 32768 pids. " 
      >> ./log 

0 个答案:

没有答案