Skip to main content

Posts

Showing posts from May, 2016

When you come to a fork() in the code, take it!

Linux is a multi-user, multi-tasking based system, which means that even a computer as small as the Raspberry Pi, can be used by multiple users simultaneously and there can be multiple processes executing (seemingly) all at once. For example, here are all the processes currently running for the user pi: pi@raspberrypi ~ $ ps -fu pi UID        PID  PPID  C STIME TTY          TIME CMD pi        4792  4785  0 Mar11 ?        00:00:04 sshd: pi@pts/0    pi        4793  4792  0 Mar11 pts/0    00:00:04 -bash pi        6137  6130  0 00:30 ?        00:00:00 sshd: pi@pts/1    pi        6138  6137  1 00:30 pts/1    00:00:01 -bash pi        6185  4793  0 00:32 pts/0    00:00:00 tail -f /var/log/messages pi        6186  6138  0 00:32 pts/1    00:00:00 ps -fu pi Using a time sharing CPU scheduler and virtual memory, each process on Linux is led to believe that it has the whole computer all to itself, even if in reality the Linux operating system kernel is busy managing resources in the

A Host by any other Name

In the previous two episodes about IP networking, we have seen a lot about raw addresses and port-numbers, because that is how the networking stack operates internally. But this is not how we interact with the Internet in real life. Except for trouble-shooting, we don’t typically use raw addresses and IDs but rather names. For example, instead of http://173.194.113.115:80 , we would enter http://www.google.com . In the earliest days of the Internet, people kept a list of name to IP address mappings on each computer connected to the network, similar to having each a copy of a phone book. The remnants of this file still exists today on Linux in /etc/hosts for some special local default addresses. pi@raspberrypi ~ $ cat /etc/hosts 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback 127.0.1.1 raspberrypi Beyond that, it is hardly used for name management except for the smallest networks with only up to a few hosts with static IP addresses. Domain Name System (D

A Matter of Protocol

Today, we are taking a look at the TCP/IP Internet protocols by using a few commands which allow us to see what is going on in the Linux kernel, all the way down to the Ethernet wire. For example, the basic ping command we have seen in a previous post might result in the following sequence of packets sent on the Ethernet port of the Raspberry Pi: ARP, Request who-has 192.168.1.143 tell 192.168.1.148, length 28 ARP, Reply 192.168.1.143 is-at c4:2c:03:1c:f2:2e, length 46 IP 192.168.1.148 > 192.168.1.143: ICMP echo request, id 17785, seq 1, length 64 IP 192.168.1.143 > 192.168.1.148: ICMP echo reply, id 17785, seq 1, length 64 IP 192.168.1.148 > 192.168.1.143: ICMP echo request, id 17785, seq 2, length 64 IP 192.168.1.143 > 192.168.1.148: ICMP echo reply, id 17785, seq 2, length 64 But before we are trying to understand what is going on here, a brief excursion into the history and theory of packet networking. In the 1960ies, researchers were starting to think of