Network and Pthread Programming on Unix and Other Platforms

1.1  Introduction to UNIX / POSIX Command Shells   New!  

Documentation on the Korn shell.

Documentation on the Bourne shell.

Documentation on the tcsh shell.

Documentation on fork(2) and exec(2) UNIX system calls (process and executable image initiation).

1.2  Introduction to POSIX Multi-threaded Programming (PThreads)   New!  

Documentation on pthread_create(3thr) and pthreads(2) POSIX threads system calls (threads on Solaris).

Example code for the creation of POSIX threads. For documentation on multi-threaded programming visit the electronic documentation pages for the different platforms below. My favorite documentation place for pthreads is the IRIX 6.5 site. Incidentally, this place has good discussion on multi-processor parallelism, as well. The mother-load of documentation is in the Opengroups's site.

1.3  Measuring Time on UNIX Accurately and Efficiently

On UNIX there are several methods to measure elapsed time. Popular methods use clock(3C), gettimeofday(3C), and clock_gettime(3R). clock_gettime(3R) is sufficiently accurate for most purposes and it is portable (POSIX). On Solaris 2.4 and above one may use gethrtime(3C) which is by far the most efficient and accurate method. gethrtime(3C) is a ``fast'' system call which samples directly a hardware register, the cycle counter. This register is incremented at each CPU clock tick. It has a sub-micro-second resolution and it introduces very little overhead when used. The resolutions of gettimeofday(3C), clock_gettime(3R), and gethrtime(3C) is shown here (color .ps) and here (monochrome .ps). More information on high-resolution time-stamping techniques can be found here.

1.4   Significant Operating Systems

The latest Single UNIX Specification by the OpenGroup Organization . This is the official UNIX® site.

The latest IEEE Std 1003.1-2001 IEEE POSIX Standard (Open Operating Systems). This is the present and future of industrial-strength operating systems. All UNIX and most operating systems providers (including Linux, MS and Apple) are working towards full compliance with this standard. POSIX compliant system now include IBM mainframes, Compaq's OpenVMS (formely DEC), from supercomputers all the way down to PCs.

A chapter on FreeBSD . Check also www.FreeBSD.org for the source and utilities of this system.

A chapter on MACH . Check also MACH home page at CMU.

A chapter on NachOS .

1.4  Example Code for POSIX (Berkeley) Socket Programming

Recovering information on the UNIX environment is part of your training. I suggest you to become familiar with a project building utility, such as, UNIX make and with a revision control system, such as, RCS. Eventually you will have to deal with debugging. I suggest you to learn dbx or whichever debugger is available on the platform of your choice. A good program development editor is Xemacs, EMACS, or vi and its cousins. Xemacs (or EMACS) offers a rich array of options for editing programming code. Finally, I suggest you to use ANSI C or ANSI C++ for your developments needs.

System Calls Study the following functions (inside the parenthesis is the manual section where this function belongs):

  1. socket(3N);
  2. bind(3N);
  3. getpeername(3N); getsockname(3N);
  4. getprotobyname(3N); gethostbyname(3N); gethostbyaddr(3N); getservbyname(3N);
  5. htonl(3N); htons(3N); inet_addr(3N); inet_ntoa(3N);
  6. listen(3N);
  7. accept(3N);
  8. connect(3N);
  9. send(3N); sendto(3N);
  10. recv(3N); recvfrom(3N);
  11. read(2); write(2);
  12. poll(2); select(3C);
  13. fork(2); exec(2);

Example code for TCP based server and client programming. Study the code and use the UNIX man command to obtain documentation on the functions these two programs use.

Tunning TCP for Higher-Performance TCP implementations can achieve higher throughput by employing newer proposed standards, including, ``Path MTU Discovery'' (RFC1191) for the discovery of the maximum possible TCP segment size along a given route and ``Large Windows extensions to TCP'' (RFC1323) for the support of TCP congestion windows larger than the default 64KB. TCP Tunning is an encyclopedic article on how to tune current TCP implementations to achieve higher throughput. Several RFCs have been published discussing and proposing ways to increase TCP's performance (throughput).

The UDP standard is defined in RFC-768. UDP is the datagram service provided by the TCP/IP protocol stack.

Example code for UDP based server and client programming. Study the code and use the UNIX man command or the network programming references to obtain documentation on the system calls these two programs use.

The Internet Protocol (IP) standard is described in RFC-791.

1.2  Introduction to IP Multi-casting

Intro IP Multi-casting is based on UDP sockets and it is defined officially in RFC1112 Example code snippets to initiate IP multi-casting and some related information on multi-casting can be found here .

Multicast Tutorials CISCO has a number of good tutorials on Multicasting as well as, in almost any other imaginable networking topic. Another CISCO site on multicasting.

A mild introduction to IP multi-casting can be found in the article #1 and tutorial #2. This tutorial discusses other protocols that can be developed on top or side-by-side with multicasting.

For multi-casting in PCs environments try this article. Multicasting can be implemented to any packet-switching network, such as ATM, Frame-Relay, X.25, ISDN, Switched-Multimegabit, etc.

1.5  Documentation Resources for Berkeley Socket Programming

A discussion on sockets and client/server programming we used in class.

A mild introduction to Berkeley Sockets programming.

Tutorial on Berkeley Sockets programming.

A more extensive tutorial on Berkeley Sockets.

Introduction to Inter-Process Communication on UNIX 4.4BSD.

Advanced discussion on Inter-Process Communication on UNIX. This is a very comprehensive tutorial for 4.4BSD networking services.

A Pocket guide to sockets.

The definitive reference for Networking Services (including the popular Berkeley Sockets) supported by open systems, is the Networking Services (XNS), Issue 5.2 of the Opengroup Organization for open standards.

The Single UNIX® Specification, Version 2, the definitive references for system calls on open UNIX® systems.

Sun Microsystem's documentation center. Select the Solaris version installed on your platform and move to the ``Software Developer Collection.'' Then select to view the ``Network Interface Guide.''

SGI's technical documentation library. Again, select the IRIX version you are using and search for ``sockets.''

HP's technical documentation library.

Compaq's documentation site for Tru64 UNIX.

PC ``sockets'' dirty-socks library. Other tutorials in www.sockets.com and here.

TCP/IP Resources List.

Decent information on using UNIX.

Information about using UNIX (CIS handouts).

Good reference material on C pointers.

Publicly Available Standard by ISO/IEC Councils.

ISO/ANSI C. The C rational.

ISO/IEC 14882: Programming Language C++ . The Programming Language C++ Standard Draft.

Links on C++.