4 Linux Systems Programming m4 Slides
4 Linux Systems Programming m4 Slides
Chris Brown
In This Module
Time
Representations, conversions
Demonstrations
Time zone and locale
Process times
Command Line Arguments
Boolean option
(verbose) Non-option
arguments
Numeric option Text option
(set block size) (output file name)
Combining Options
Equivalent
ls l -a commands ls la
$ export FOO=BAR
Environment Variable $ env | grep FOO
(usually upper-case) FOO=BAR
The Environment
environ
HOME=/home/chris\0
SHELL=/bin/bash\0
TERM=xterm\0
FOO=BAR\0
NULL
Listing the Environment
#include <stdio.h>
getenv(name)
The environment
variable's name
Returns the
associated string value
or NULL if none
Inheriting the Environment
The environment is normally
passed down from a process
to its children
and their children in turn
Representations of time
Conversions
Kernel
What Time Is It?
time_t
Returns the address
of a struct tm
("broken down" time)
The tm Structure
struct tm {
int tm_sec; /* seconds */
int tm_min; /* minutes */
int tm_hour; /* hours */
int tm_mday; /* day of the month */
int tm_mon; /* month */
int tm_year; /* year */
int tm_wday; /* day of the week */
int tm_yday; /* day in the year */
int tm_isdst; /* daylight saving time */
};
Demonstration
Kernel
Converting to a Human-Readable Form
ctime(t)
time_t
Returns a printable string
in the local time zone
"Sunday 8 March"
"Sonntag 8 Mrz"
"Dimanche 8 Mars"
Locales
A locale defines conventions for displaying money amounts, times and dates
and numbers
- Defined by files under /usr/share/locale
May need to install additional languages, e.g. on Ubuntu:
- sudo apt-get install language-pack-de
Specify the locale by setting the environment variable LC_ALL
- LC_ALL=de_DE.utf8; export LC_ALL
Make the program aware of the locale:
- setlocale(LC_ALL, "")
Converting Time to a Locale-Specific String
strftime(buf, 1000, "%A %e %B", tm)
clock()
times(buf)
struct tms
struct tms {
clock_t tms_utime; /* user time */
clock_t tms_stime; /* system time */
clock_t tms_cutime; /* user time of children */
clock_t tms_cstime; /* system time of children */
};
Kernel Space and User Space
Application Programs
sqrt() printf() write()
User
space
Standard
Library
The environment
Time
Representations (time_t, broken-down time)
Conversions
Printable representations, timezones, locales
Process times (system time and user time)
Coming up in the Next Module
Processes
Pipes