리눅스 자식생성 스크립트 proliferation.sh

리눅스 자식생성 스크립트 proliferation.sh

1 소스 코드[ | ]

#!/bin/bash

if [ $# -eq 0 ]; then exit; fi
if [ $1 -lt 1 ]; then exit; fi

generation=$(($1 - 1))
bash ./$0 $generation &
bash ./$0 $generation &
bash ./$0 $generation &

sleep 600

2 실습[ | ]

[root@zetawiki ~]# bash proliferation.sh 3 &
[1] 22712
[root@zetawiki ~]# pstree 22712 -npA
bash(22712)-+-bash(22713)-+-bash(22744)---sleep(22760)
            |             |-bash(22745)---sleep(22754)
            |             |-bash(22746)---sleep(22763)
            |             `-sleep(22748)
            |-bash(22714)-+-bash(22717)---sleep(22726)
            |             |-bash(22718)---sleep(22736)
            |             |-bash(22719)---sleep(22764)
            |             `-sleep(22720)
            |-bash(22715)-+-bash(22721)---sleep(22730)
            |             |-bash(22723)---sleep(22740)
            |             |-bash(22731)---sleep(22747)
            |             `-sleep(22732)
            `-sleep(22716)
[root@zetawiki ~]# ps -ef | grep proliferation | grep -v grep
root     22712 21497  0 11:39 pts/0    00:00:00 bash proliferation.sh 3
root     22713 22712  0 11:39 pts/0    00:00:00 bash ./proliferation.sh 2
root     22714 22712  0 11:39 pts/0    00:00:00 bash ./proliferation.sh 2
root     22715 22712  0 11:39 pts/0    00:00:00 bash ./proliferation.sh 2
root     22717 22714  0 11:39 pts/0    00:00:00 bash ././proliferation.sh 1
root     22718 22714  0 11:39 pts/0    00:00:00 bash ././proliferation.sh 1
root     22719 22714  0 11:39 pts/0    00:00:00 bash ././proliferation.sh 1
root     22721 22715  0 11:39 pts/0    00:00:00 bash ././proliferation.sh 1
root     22723 22715  0 11:39 pts/0    00:00:00 bash ././proliferation.sh 1
root     22731 22715  0 11:39 pts/0    00:00:00 bash ././proliferation.sh 1
root     22744 22713  0 11:39 pts/0    00:00:00 bash ././proliferation.sh 1
root     22745 22713  0 11:39 pts/0    00:00:00 bash ././proliferation.sh 1
root     22746 22713  0 11:39 pts/0    00:00:00 bash ././proliferation.sh 1
[root@zetawiki ~]# ps -ef | grep proliferation | grep -v grep | awk '{print $2}' | xargs kill -9
[1]+  Killed                  bash proliferation.sh 3
→ 또는 kill -9 -22712
[root@zetawiki ~]# ps -ef | grep proliferation
root     23106 21497  0 11:43 pts/0    00:00:00 grep proliferation

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}