Skip to content

Instantly share code, notes, and snippets.

View danog's full-sized avatar
🇺🇦
#StandWithUkraine

Daniil Gentili danog

🇺🇦
#StandWithUkraine
View GitHub Profile
@danog
danog / concurrency.md
Created January 5, 2024 01:20
An overview of concurrency and parallelism

Sorry if I'm stating the obvious for some, but I feel like many people are lacking a good comprehension of what is concurrency vs parallelism, and since Operating Systems was my favorite uni exam decided to write up a small refresher, a few years after finishing it :D

Put (very) simply, a scheduler is a piece of software that schedules execution of some code on the CPU.

The OS scheduler is a preemptive scheduler that runs in the kernel and schedules OS threads for execution on the CPU.

Since there are usually many threads waiting for CPU time, and only one CPU (let's consider just single-core systems), the scheduler gives each thread a little time slice, and once that expires, it interrupts execution of the thread starts thr next one in the queue. Only one thread is physically running at any given moment, and the entire set of all active threads is considered to be running concurrently.

The ability to interrupt execution of threads even if they don't explicitly return control to the scheduler (such as by

Keybase proof

I hereby claim:

  • I am danog on github.
  • I am danog (https://keybase.io/danog) on keybase.
  • I have a public key ASDZoMn8FR2yTYuqQNLAYcUOdJvbgfrBwT9Lda3DloNaDQo

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am danog on github.
  • I am danog (https://keybase.io/danog) on keybase.
  • I have a public key whose fingerprint is C0A1 F63D 5208 5C66 570C D56D 2599 0030 8520 B573

To claim this, I am signing this object:

@danog
danog / name.sh
Last active November 12, 2017 20:29
Just the name
#!/bin/sh
echo "This script prints just the script's name without its full path.
`basename $0`
"
@danog
danog / sudo.sh
Created April 14, 2015 20:19
Automatic sudo request
#!/bin/bash
# Automatic sudo request
if [ $(id -u) -ne 0 ]; then
sudo $0 $* || echo "I am not sudo."
exit $?
fi
echo "I am sudo."
@danog
danog / update.sh
Last active August 29, 2015 14:19
Update Debian/Ubuntu system
#!/bin/bash
# Debian/Ubuntu updater script
# Created by Daniil Gentili
if [ "$1" = "--help" ]; then
echo "Debian/Ubuntu upgrade script created by Daniil Gentili.
Usage: just type
update.sh
@danog
danog / music.sh
Last active August 29, 2015 14:19
MP3 Player script
#!/bin/bash
# Script to play mp3 files.
# By Daniil Gentili
if [ "$1" = "--help" ]; then echo "Music player by Daniil Gentili.
Usage: `basename $0` [ Options ] file1 file2 ...
If called with no arguments you will be asked to select the file(s) to play.
Options:
@danog
danog / crontab.sh
Last active August 29, 2015 14:18
Edit crontab in a script
#!/bin/bash
# Script to edit crontab by Daniil Gentili
echo "Editing crontab..."; echo "$(crontab -l)
$*" | crontab - && echo "Crontab edited successfully." || echo "Couldn't edit crontab."
@danog
danog / dropbox_youtube_dl.sh
Last active March 13, 2022 13:22
Script to download videos from YouTube using Dropbox and IFTTT automation (IFTTT recipe: https://ifttt.com/recipes/277403-download-every-youtube-video-you-add-to-your-watch-later-playlist-automatically)
#!/bin/bash
### Original script by Geoffeg, modified by Roblight and later by me (alias me='alias Danog='Daniil Gentili'')
### How to install this script:
### wget https://gist.githubusercontent.com/danog/f86bf3113e1644b4d5d9/raw/dropbox_youtube_dl.sh -O ~/dropbox_youtube_dl.sh && chmod 755 ~/dropbox_youtube_dl.sh && ~/dropbox_youtube_dl.sh --install
###
### IFTTT Recipe URL: https://ifttt.com/recipes/277403-download-every-youtube-video-you-add-to-your-watch-later-playlist-automatically
if [ "$1" = "--install" ]; then
if [ -f /usr/local/bin/youtube-dl ]; then echo "Youtube-dl already installed."; else echo "Installing youtube-dl..."; sudo curl https://yt-dl.org/downloads/2015.04.03/youtube-dl -o /usr/local/bin/youtube-dl && sudo chmod a+x /usr/local/bin/youtube-dl && echo "YouTube-dl installed successfully." || echo "Couldn't install YouTube-dl."; fi
@danog
danog / dropbox_inst.sh
Last active May 20, 2016 17:29
Dropbox headless installation script
#!/bin/bash
# Dropbox installation script by Daniil Gentili.
if [ -f ~/.dropbox-dist/dropboxd ]; then echo "Dropbox already installed."; else
echo "Installing Dropbox..."
platform=`uname -m | tr '[A-Z]' '[a-z]'`
case $platform in
"x86_64")
DROPBOXURL="http://www.dropbox.com/download?plat=lnx.x86_64"
;;