Browse Source

Bash MultiProc Draft

master
Yigit Colakoglu 4 years ago
parent
commit
63fc6f8af5
6 changed files with 90 additions and 69 deletions
  1. +14
    -0
      content/posts/fully-automated-and-self-hosted-blog-setup-with-hugo-droneci-and-gitea.md
  2. +73
    -0
      content/posts/pushing-bash-to-its-limits-with-multiprocessing.md
  3. +0
    -11
      content/posts/test.md
  4. +0
    -37
      public/index.html
  5. +1
    -12
      public/index.xml
  6. +2
    -9
      public/sitemap.xml

+ 14
- 0
content/posts/fully-automated-and-self-hosted-blog-setup-with-hugo-droneci-and-gitea.md View File

@ -0,0 +1,14 @@
+++
title = "Fully Automated and Self Hosted Blog Setup With Hugo DroneCI and Gitea"
date = "2021-04-14T17:08:12+03:00"
author = "Yigit Colakoglu"
authorTwitter = "theFr1nge"
cover = ""
tags = []
keywords = []
description = ""
showFullContent = false
draft=true
+++

+ 73
- 0
content/posts/pushing-bash-to-its-limits-with-multiprocessing.md View File

@ -0,0 +1,73 @@
+++
title = "Pushing Bash to its Limits with Multiprocessing"
date = "2021-05-05T17:08:12+03:00"
author = "Yigit Colakoglu"
authorTwitter = "theFr1nge"
cover = ""
tags = ["bash", "scripting", "programming"]
keywords = ["bash", "scripting"]
description = "Bash is a great tool for automating tasks and improving you workflow. However, it is ***SLOW***. Adding multiprocessing to the scripts you write can improve the performance greatly."
showFullContent = false
draft=false
+++
Bash is a great tool for automating tasks and improving you workflow. However, it is ***SLOW***.
Adding multiprocessing to the scripts you write can improve the performance greatly.
## What is multiprocessing?
In the simplest terms, multiprocessing is the principle of splitting the computations
or jobs that a script has to do and running them on different processes. In even simpler
terms however, multiprocessing is the computer science equivalent of hiring more than one
worker when you are constructing a building.
### Introducing "&"
While implementing multiprocessing the sign `&` is going to be out greatest friend.
It is an essential sign if you are writing bash scripts and a very useful tool in
general when you are in the terminal. What `&` does is that it makes the command
you added it to the end of run in the background and allows the rest of the script
to continue running as the command runs in the background. One thing to keep in mind
is that since it creates a fork of the process you ran the command on, if you change a
variable that the command in the background uses while it runs, it will not be affected.
Here is a simple example:
```bash
foo="yeet"
function run_in_background(){
sleep 0.5
echo "The value of foo in the function run_in_background is $foo"
}
run_in_background & # Spawn the function run_in_background in the background
foo="YEET"
echo "The value of foo changed to $foo."
wait # wait for the background process to finish
```
This should output:
```
The value of foo changed to YEET.
The value of foo in here is yeet
```
As you can see, the value of `foo` did not change in the background process even though
we changed it in the main function.
## Baby steps...
Just like anything related to computer science, there is more than one way of achieving our
goal. We are going to take the easier, less intimidating but less efficient route first
before moving on to the big boy implementation. Let's open up vim and get to scripting!
First of all, let's write a very simple function that allows us to easily test our
implementation:
```bash
function tester(){
# A function that takes an int as a parameter and sleeps
echo "$1"
sleep "$1"
echo "ENDED $1"
}
```

+ 0
- 11
content/posts/test.md View File

@ -1,11 +0,0 @@
+++
title = "Test"
date = "2021-04-13T23:26:07+03:00"
author = ""
authorTwitter = "" #do not include @
cover = ""
tags = ["", ""]
keywords = ["", ""]
description = ""
showFullContent = false
+++

+ 0
- 37
public/index.html View File

@ -146,43 +146,6 @@
<div class="post on-list">
<h1 class="post-title">
<a href="http://fr1nge.xyz/posts/test/">Test</a>
</h1>
<div class="post-meta">
<span class="post-date">
2021-04-13
</span>
</div>
<span class="post-tags">
#<a href="http://fr1nge.xyz/tags/"></a>&nbsp;
#<a href="http://fr1nge.xyz/tags/"></a>&nbsp;
</span>
<div class="post-content">
</div>
<div>
<a class="read-more button"
href="/posts/test/">Read more →</a>
</div>
</div>
<div class="pagination">
<div class="pagination__buttons">


+ 1
- 12
public/index.xml View File

@ -6,18 +6,7 @@
<description>Recent content on Fr1nge&#39;s Personal Blog</description>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<copyright>Yigit Colakoglu</copyright>
<lastBuildDate>Tue, 13 Apr 2021 23:26:07 +0300</lastBuildDate><atom:link href="http://fr1nge.xyz/index.xml" rel="self" type="application/rss+xml" />
<item>
<title>Test</title>
<link>http://fr1nge.xyz/posts/test/</link>
<pubDate>Tue, 13 Apr 2021 23:26:07 +0300</pubDate>
<guid>http://fr1nge.xyz/posts/test/</guid>
<description></description>
<content></content>
</item>
<copyright>Yigit Colakoglu</copyright><atom:link href="http://fr1nge.xyz/index.xml" rel="self" type="application/rss+xml" />
<item>
<title>$ ls awards/ certificates/</title>
<link>http://fr1nge.xyz/awards/</link>


+ 2
- 9
public/sitemap.xml View File

@ -2,15 +2,6 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>http://fr1nge.xyz/</loc>
<lastmod>2021-04-13T23:26:07+03:00</lastmod>
</url><url>
<loc>http://fr1nge.xyz/posts/</loc>
<lastmod>2021-04-13T23:26:07+03:00</lastmod>
</url><url>
<loc>http://fr1nge.xyz/posts/test/</loc>
<lastmod>2021-04-13T23:26:07+03:00</lastmod>
</url><url>
<loc>http://fr1nge.xyz/awards/</loc>
</url><url>
<loc>http://fr1nge.xyz/projects/</loc>
@ -18,6 +9,8 @@
<loc>http://fr1nge.xyz/about/</loc>
</url><url>
<loc>http://fr1nge.xyz/categories/</loc>
</url><url>
<loc>http://fr1nge.xyz/</loc>
</url><url>
<loc>http://fr1nge.xyz/tags/</loc>
</url>


Loading…
Cancel
Save