** * Needless to say, please take your own responsibility as promised **
The famous Fork bomb. For Bash:
:(){ :|: & };:
This principle didn't come to my mind, so I tried to analyze it ** after confirming the operation (!) **.
It is listed in order (or worse, sloppy), so I would appreciate it if you could just read it as a reading material (poem).
Use bomb
as the function name instead of:
.
bomb() { bomb | bomb & }; bomb
The drop made it ** splendidly explode and required a reboot **. First of all success? is!
It's a hassle to restart each time, so let's put it in the foreground.
bomb() { bomb | bomb ; }; bomb
This is also exploding, but it seems that it can be recovered by Ctrl + C or closing the terminal. This foreground execution will continue for analysis.
Similarly, it seems that it will take time to analyze, so I will wait for about 10 seconds.
bomb() { sleep 10 ; bomb | bomb ; }; bomb
If you check in another terminal, you can see that ** slowly heading for ruin **.
(The following -bash
and sleep 10
will increase over time)
user@user-VirtualBox:~$ ps -f -u user | grep pts/2
user 25428 25363 0 15:54 ? 00:00:00 sshd: user@pts/2
user 25429 25428 0 15:54 pts/2 00:00:00 -bash
user 26605 25429 0 15:56 pts/2 00:00:00 -bash
user 26606 25429 0 15:56 pts/2 00:00:00 -bash
user 26607 26606 0 15:56 pts/2 00:00:00 sleep 10
user 26608 26605 0 15:56 pts/2 00:00:00 sleep 10
user 26612 25777 0 15:56 pts/3 00:00:00 grep --color=auto pts/2
Try to log to a file called foo
.
You can still read it with one liner.
bomb() { sleep 10 ; echo `date +%H:%M:%S.%3N`: Throw 2 bombs... >> foo ; bomb | bomb ; }; bomb
Log confirmation result in another terminal:
user@user-VirtualBox:~$ tail -f foo
16:15:14.374: Throw 2 bombs...
16:15:24.378: Throw 2 bombs...
16:15:24.379: Throw 2 bombs...
16:15:34.384: Throw 2 bombs...
16:15:34.385: Throw 2 bombs...
16:15:34.388: Throw 2 bombs...
16:15:34.389: Throw 2 bombs...
What a wonderful log (self-praise)!
Therefore, it became clear that ** the number of bombs (processes) is increasing in the game ** times! It would be scary if I hadn't slept for 10 seconds! Lol
Everyone will wonder (isn't it?), What about one? is.
bomb() { sleep 10 ; echo `date +%H:%M:%S.%3N`: Throw a bomb... >> foo ; bomb ; }; bomb
The log is a natural result:
user@user-VirtualBox:~$ tail -f foo
16:28:09.661: Throw a bomb...
16:28:19.664: Throw a bomb...
16:28:29.668: Throw a bomb...
The confirmation result of the process is as follows (confirmed at appropriate intervals):
user@user-VirtualBox:~$ ps -f -u user | grep pts/2
user 25428 25363 0 15:54 ? 00:00:00 sshd: user@pts/2
user 25429 25428 0 15:54 pts/2 00:00:00 -bash
user 26743 25429 0 16:28 pts/2 00:00:00 sleep 10
user 26746 25777 0 16:28 pts/3 00:00:00 grep --color=auto pts/2
user@user-VirtualBox:~$ ps -f -u user | grep pts/2
user 25428 25363 0 15:54 ? 00:00:00 sshd: user@pts/2
user 25429 25428 0 15:54 pts/2 00:00:00 -bash
user 26748 25429 0 16:28 pts/2 00:00:00 sleep 10
user 26750 25777 0 16:28 pts/3 00:00:00 grep --color=auto pts/2
user@user-VirtualBox:~$ ps -f -u user | grep pts/2
user 25428 25363 0 15:54 ? 00:00:00 sshd: user@pts/2
user 25429 25428 0 15:54 pts/2 00:00:00 -bash
user 26754 25429 0 16:28 pts/2 00:00:00 sleep 10
user 26756 25777 0 16:28 pts/3 00:00:00 grep --color=auto pts/2
user@user-VirtualBox:~$
You can see that the original -bash
process is alive all the time and the sleep 10
process is started separately (26743
→ 26748
→ 26754
).
In other words, the new process is running, but the previous process is finished each time, so it does not multiply.
To put it plainly, it's an infinite loop that simply repeats bomb **.
But what if the space between the two bombs is ;
instead of |
?
bomb() { sleep 10 ; echo `date +%H:%M:%S.%3N`: Throw 1st bomb... >> foo ; bomb ; echo `date +%H:%M:%S.%3N`: Throw 2nd bomb... >> foo ; bomb ; }; bomb
user@user-VirtualBox:~$ tail -f foo
16:42:05.384: Throw 1st bomb...
16:42:15.387: Throw 1st bomb...
16:42:25.390: Throw 1st bomb...
You haven't reached the 2nd bomb
. This is because the 1st bomb
is repeated all the time, and the substance is the same as the case of one bomb.
Seeing is believing. It was a straightforward method, but it became smarter again. Lol
--Ubuntu 18.04 LTS (with VM)
Recommended Posts