TL;DR
I don't strive to simply complete my work, I strive to perfect my craft.
When you do that, you wouldn't be satisfy with just able to solve the problem. You will ask if there are any other better ways to do the same thing ? What is the pros and cons, caveats and quirks and workarounds you need to deal with for each solutions. That's how you improve more than just the work assigned to you. Real industrial works are good starting ground, but often they are limited by time, resources and cost. If you want to investigate further, you need to further complicate the problem. You need to look beyond the problem and investigate. That's how to improve significantly.
Honestly speaking, what I have demonstrate in this Bash challenge is nothing difficult. All the skill set requires is what is required of a Unix software engineer.
exec command is found in a lot of programming languages, but be careful what you are reading. Quite a few languages don't exhibit the real
exec that is happening on a Unix system. In an Unix OS course, you will learn
fork() and
exec() in C. Here is a tutorial on it
https://ece.uwaterloo.ca/~dwharder/icsrts/Tutorials/fork_exec/
There are quite a few variants of
exec but they all does the same thing. Reload the specified image into the current process. We do that in Unix C because it often follows a fork process. Fork is the Unix way of creating new processes from the current process. These new processes are children process with their parent process set as the current one. This is also the start of multiprocessing.
Just this simplistic shell code would have already demonstrated the above.
The current shell is first forked to create child process, then the child process run an exec command to load the binary image of
ls and totally replace the forked process of
bash. All these knowledge comes from understanding Unix programming.
Here is a demonstration. In one terminal, I was running this
Code:
while true; do ls; done >/dev/null
In another terminal, I am running this
Code:
$ while true; do pstree | egrep -B 2 '\bls\b' | grep -v grep; echo ------------------------------------; done
| |-+= 01790 root login -fp davidktw
| | \-+= 01792 davidktw -bash
| | \--= 83082 davidktw (ls)
------------------------------------
| |-+= 01790 root login -fp davidktw
| | \-+= 01792 davidktw -bash
| | \--= 83109 davidktw (ls)
------------------------------------
| |-+= 01790 root login -fp davidktw
| | \-+= 01792 davidktw -bash
| | \--= 83135 davidktw (ls)
------------------------------------
------------------------------------
| |-+= 01790 root login -fp davidktw
| | \-+= 01792 davidktw -bash
| | \--= 83188 davidktw (ls)
------------------------------------
Notice the
ls command parent is the
bash shell, and despite the ls command process id is changing all the time, the shell process id (
01792) never change.
The Fibonacci demonstration is just leveraging on the dynamic programming solution of it. You can of course do it for a lot of other programming solutions, but it is not meant for actual use, because you will almost never want to write your code the way for the challenge, and rather just use a simple loop construct to complete it. I am just creating constraint to force into the usage of this technique.
If you feel this is difficult, would the 2 Quicksort techniques that I have written in another thread be any easier for you ?
Feel free to read them at
https://forums.hardwarezone.com.sg/...odes-to-share-for-fun.6832706/#post-144837640
There are 2 techniques I have demonstrated, one is functional, the other is imperative and faster.
Too bad shell cannot use multithreading, which is not the same as multiprocessing. I do hope you understand the differences, because it will allow me to easily parallelise the quicksort in an efficient manner.
I hope you have also tried on the challenge questions. I set them for anyone whom is keen to learn.