Commit 317d9f97 authored by nilsl's avatar nilsl

Merge branch 'master' of gitlab.ethz.ch:thealternative/courses

parents 03ca189c 7288ff34
# LaTeX traces
*.log
*.toc
*.aux
*.out
*-blx.bib
*run.xml
*.fdb_latexmk
*.fls
*.synctex.gz
*.snm
*.nav
# Bibtex traces
*.bak
*.blg
*.bbl
# PythonTeX traces and binaries
pythontex-*/
*.pytxcode
# Gedit
*~
\documentclass[aspectratio=169]{beamer}
\usepackage[T1]{fontenc} %pipes don't display properly without this
\usepackage[T1]{fontenc} % the pipe character doesn't display properly without this
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{color}
\usepackage{datapie}
\usepackage{minted} % COMPILE WITH `pdflatex -shell-escape`!
\usepackage{multicol}
\usepackage{upgreek}
\usepackage{siunitx} %pretty measurement unit rendering
\usepackage{hyperref} %enable hyperlink for urls
\usepackage{siunitx} % pretty measurement unit rendering
\usepackage{hyperref} % enable hyperlink for URLs
\usepackage{lmodern}
\usepackage{setspace}
\usepackage[os=win]{menukeys} % by default keys are given for MacOS
\usefonttheme[onlymath]{serif}
\setcounter{MaxMatrixCols}{20}
......@@ -26,9 +28,9 @@
%Define generic colors
\definecolor{slg}{gray}{0.25}
\definecolor{lg}{gray}{0.55}
\definecolor{lg}{gray}{0.53}
\definecolor{vlg}{gray}{0.73}
\definecolor{tlg}{gray}{0.9}
\definecolor{tlg}{gray}{0.91}
%Define data colors
\definecolor{mygreen}{rgb}{0,0.6,0}
......
#!/usr/bin/env bash
pdflatex slides.tex
pdflatex -shell-escape slides.tex
bibtex slides
pdflatex slides.tex
pdflatex slides.tex
pdflatex -shell-escape slides.tex
pdflatex -shell-escape slides.tex
Name,percent
Unix,70.5
Windows,29.5
Unix,71.4
Windows,28.6
Name,percent
Apache,44.0
Nginx,30.7
Cloudflare Server,11.2
Microsoft-IIS,8.2
other,5.9
Apache,40.5
Nginx,31.7
Cloudflare Server,13.2
Microsoft-IIS,7.8
other,5.8
No preview for this file type
\input{header}
\input{../.style/header}
\title{Free and Open Source Software}
\author{Horea Christian}
......@@ -72,7 +72,7 @@
\textcolor{ldorange}{$\sim$1970-1980:}
\begin{itemize}
\item Increasingly easy to withold control (e.g. binary-only distribution)
\item United States vs. IBM (1969): “Bundled Software is anticompetitive”
\item United States vs. IBM (1969, dropped 1982): “Bundled Software is anticompetitive”
\item Computer Software Copyright Act (1980): “Software is patentable”
\end{itemize}
\end{frame}
......@@ -193,6 +193,11 @@
% Proprietary Software is Often Malware https://www.gnu.org/proprietary/
\end{frame}
\begin{frame}{Sustainability}
\begin{center}
“the quality of being able to continue over a period of time“
\end{center}
The Software:
\begin{itemize}
\item depends on no single entity for its continuity.
......@@ -335,7 +340,7 @@
\vspace{-0.75em}
\centering\tiny
\DTLpiechart{radius=0.235\textheight,variable=\quantity,innerlabel={\DTLpiepercent\%},outerlabel=\name,cutaway={1-2}}{server}{\name=Name,\quantity=percent}
\caption{Web Server Market Share 2019-10-04 via \href{http://w3techs.com/technologies/overview/web_server/all}{w3techs}}
\caption{Web Server Market Share 2020-02-26 via \href{http://w3techs.com/technologies/overview/web_server/all}{w3techs}}
\end{figure}
\column{0.5\linewidth}
\begin{figure}[htbp]
......@@ -344,7 +349,7 @@
\DTLsetpiesegmentcolor{1}{green!40}
\DTLsetpiesegmentcolor{2}{red!40}
\DTLpiechart{radius=0.265\textheight,variable=\quantity,innerlabel={\DTLpiepercent\%},outerlabel=\name,cutaway={2}}{os}{\name=Name,\quantity=percent}
\caption{Website OS Market Share 2019-10-04 via \href{http://w3techs.com/technologies/overview/operating_system/all}{w3techs}}
\caption{Website OS Market Share 2020-02-26 via \href{http://w3techs.com/technologies/overview/operating_system/all}{w3techs}}
\end{figure}
\end{columns}
\end{frame}
......@@ -385,7 +390,7 @@
\caption{\copyright Red Hat, Inc.}
\end{figure}
\begin{itemize}
\item Founded 1993
\item Founded 1993, subsidiary of IBM since 2019
\item 2015--2018 stock price $\mathrm{\upbeta_{RHT}=1.16}$ (e.g. $\mathrm{\upbeta_{MSFT}=1.22}$)
\item Very diverse open source products, e.g. OpenStack, RHEL, CloudForms
\end{itemize}
......@@ -431,7 +436,7 @@
\item Come to the next “Linux Days” events:
\textcolor{lg}{\url{http://thealternative.ch/}}
\item Join the next “Stammtisch”:\\
\textcolor{lg}{18:00 Thursday, March 12 - Learning Spaces on the E Floor of ETH Building CHN Universitätestrasse 16}
\textcolor{lg}{18:00 Thursday, March 5 - Katholische Hochschulgemeinde Zürich AKI, 2nd floor, Hirschengraben 86, 8001}
\item Give us feedback!\\
\textcolor{lg}{\url{https://feedback.thealternative.ch/}}
\end{itemize}
......
......@@ -25,6 +25,8 @@ git clone https://gitlab.ethz.ch/thealternative/courses.git
You can find the course materials in the various subdirectories of this repository.
You need `git-lfs` installed for the larger files to download as expected.
# For TheAlternative Members
This repository is kept up to date by TheAlternative members. If you teach a course, please add your slides and supplementary material, such as exercise sheets, to this repo. Do not upload any private files, as this repository is publicly visible.
#!/bin/bash
printf "Building Main Presentation... "
pandoc -t beamer --template template.tex --listings pres.md -o pres.pdf --pdf-engine pdflatex
echo "Done"
int
main(int argc, char **argv) {
int arr[10];
arr[11] = 1;
return 0;
}
#include<pthread.h>
pthread_mutex_t lock1 = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t lock2 = PTHREAD_MUTEX_INITIALIZER;
void *
thread1(void *arg __attribute__((unused))) {
pthread_mutex_lock(&lock1);
pthread_mutex_lock(&lock2); //Lock-Order-Inversion between here...
pthread_mutex_unlock(&lock2);
pthread_mutex_unlock(&lock1);
return NULL;
}
void *
thread2(void *arg __attribute__((unused))) {
pthread_mutex_lock(&lock2);
pthread_mutex_lock(&lock1); // ... and here!
pthread_mutex_unlock(&lock1);
pthread_mutex_unlock(&lock2);
return NULL;
}
int
main(int argc, char **argv) {
pthread_t t1, t2;
pthread_create(&t1, NULL, thread1, NULL);
pthread_create(&t2, NULL, thread2, NULL);
pthread_join(t1, NULL);
pthread_join(t2, NULL);
return 0;
}
#include<stdlib.h>
int
main(int argc, char **argv) {
int *p;
p = malloc(sizeof(int));
return 0;
}
#include<pthread.h>
volatile int inc;
void *
thread(void *arg __attribute__((unused))) {
for (int i = 0; i < 65536; i++)
inc++;
return NULL;
}
int
main(int argc, char **argv) {
pthread_t t1, t2;
pthread_create(&t1, NULL, thread, NULL);
pthread_create(&t2, NULL, thread, NULL);
pthread_join(t1, NULL);
pthread_join(t2, NULL);
return 0;
}
#include<stdlib.h>
int
main(int argc, char **argv) {
int *ip;
ip = malloc(sizeof(int));
free(ip);
*ip = 3;
return 0;
}
int
main(int argc, char **argv) {
int i = 32;
int j = 0xCAFFEE;
j = j << i;
return 0;
}
#include<stdio.h>
int
main(int argc, char **argv) {
int i;
if (i)
printf("Hui\n");
else
printf("Pfui\n");
return 0;
}
#include<stdio.h>
#include<stdbool.h>
#include<tgmath.h>
bool
is_prime(int number) {
int max = ((int) sqrt((double) number)) + 1;
for (int i = 2; i < max; i++)
if (!(number % i))
return false;
return true;
}
int
main(int argc, char** argv) {
int number;
scanf("%d", &number);
if (is_prime(number))
printf("%d: prime\n", number);
else
printf("%d: not prime\n", number);
return 0;
}
#include<stdio.h>
int
main(int argc, char **argv) {
FILE *f = fopen("/tmp/test", "w+");
fprintf(f, "Hello\n");
fclose(f);
printf("Done!\n");
return 0;
}
#include<stdio.h>
int
main(int argc, char **argv) {
printf("Hello World!");
return 0;
}
##
\begin{center}
{\Large \textbf{Debugging on Linux}}
\end{center}
## Print Debugging
\begin{center}
Most often, debugging is done via print... \linebreak
...But that scales poorly
\end{center}
## GDB
\begin{center}
A Debugger (such as GDB) can help here
\end{center}
# GDB
## What is GDB?
GDB is a tool to inspect your program while it is running. It allows:
- to stop program execution at any point
- step through the program
- print the value of variables
- modify variables
## Usage
Before running a program in GDB, it needs to be compiled with debug symbol.
- Available compiler flags flags are `-g`, `-g3`, `-ggdb3`
- `-ggdb3` gives the most debug information
The program can then be run under gdb: `gdb ./a.out`
## An Example...
```{.c .numberLines}
#include<stdio.h>
#include<stdbool.h>
#include<tgmath.h>
bool is_prime(int number) { /* snip */ }
int
main(int argc, char** argv) {
int number;
scanf("%d", &number);
if (is_prime(number))
printf("%d: prime\n", number);
else
printf("%d: not prime\n", number);
return 0;
}
```
## An Example...
```
$ gcc -ggdb3 simple.c -lm
$ gdb ./a.out
GNU gdb (GDB) 8.3.1
Copyright (C) 2019 Free Software Foundation, Inc.
...snip...
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...
(gdb)
```
## The Start Command
start
: starts program execution and stops it at the beginning of main
```
(gdb) start
Temporary breakpoint 1 at 0x11c7: file simple.c, line 16.
Starting program: /home/dcm/misc/debugging-on-linux/code/gdb-examples/a.out
Temporary breakpoint 1, main (argc=1, argv=0x7fffffffdf18) at simple.c:16
16 main(int argc, char** argv) {
(gdb)
```
## The Step Command
step
: executes the next line. If there's a function, it will step into it.
```
(gdb) start
Temporary breakpoint 1 at 0x11c7: file simple.c, line 16.
Starting program: /home/dcm/misc/debugging-on-linux/code/gdb-examples/a.out
Temporary breakpoint 1, main (argc=1, argv=0x7fffffffdf18) at simple.c:16
16 main(int argc, char** argv) {
(gdb) step
18 scanf("%d", &number);
(gdb)
```
## The Next Command
next
: executes the next line. If there's a function, *DO NOT* step into it.
```
(gdb) start
Temporary breakpoint 1 at 0x11c7: file simple.c, line 16.
Starting program: /home/dcm/misc/debugging-on-linux/code/gdb-examples/a.out
Temporary breakpoint 1, main (argc=1, argv=0x7fffffffdf18) at simple.c:16
16 main(int argc, char** argv) {
(gdb) step
18 scanf("%d", &number);
(gdb) next
1234567
19 if (is_prime(number))
(gdb)
```
## The Print Command
print
: prints the contents of variables. It also allows calling functions.
```
(gdb) step
18 scanf("%d", &number);
(gdb) next
1234567
19 if (is_prime(number))
(gdb) print number
$1 = 1234567
(gdb) print is_prime(number)
$2 = false
(gdb)
```
## The List Command
list
: lists the 10 lines of source code surrounding the current one
```
(gdb) next
1234567
19 if (is_prime(number))
(gdb) list
14
15 int
16 main(int argc, char** argv) {
17 int number;
18 scanf("%d", &number);
19 if (is_prime(number))
20 printf("%d: prime\n", number);
21 else
22 printf("%d: not prime\n", number);
23 return 0;
(gdb)
```
## The Break Command
break
: adds a break point, which will stop program execution when reached
```
(gdb) list
14
15 int
16 main(int argc, char** argv) {
17 int number;
18 scanf("%d", &number);
19 if (is_prime(number))
20 printf("%d: prime\n", number);
21 else
22 printf("%d: not prime\n", number);
23 return 0;
(gdb) break 22
Breakpoint 2 at 0x555555555214: file simple.c, line 22.
(gdb)
```
## The Continue Command
continue
: continues program execution until either a breakpoint is hit or the programs exits
```
(gdb) break 22
Breakpoint 2 at 0x555555555214: file simple.c, line 22.
(gdb) continue
Continuing.
Breakpoint 2, main (argc=1, argv=0x7fffffffdf08) at simple.c:22
22 printf("%d: not prime\n", number);
(gdb)
```
## The Quit Command
quit
: quits GDB, terminating the program
```
(gdb) continue
Continuing.
Breakpoint 2, main (argc=1, argv=0x7fffffffdf08) at simple.c:22
22 printf("%d: not prime\n", number);
(gdb) quit
A debugging session is active.
Inferior 1 [process 7431] will be killed.
Quit anyway? (y or n) y
$
```
## Text User Interface
GDB can also be run with a TUI: `gdb -tui ./a.out`
## Text User Interface
\begin{center}
\includegraphics[width=0.75\textwidth]{img/gdb-tui.png}
\end{center}
# Valgrind
## Quick Warning