使用 Ubuntu Linux (Debian-based) 為例,建議最少需要以下套件
$ sudo apt-get install gcc g++ gdb make manpages-dev manpages-posix manpages-posix-dev
Booting Process
開機後依序會經過下面流程
File System Architecture
Everything starts from the “root directory” (/)
UNIX Commands
Common Notations
UNIX 文件中的提示符號
Man page
$ man [section] page
#include <stdio.h> int main() { printf("Hello, World.\n"); return 0; }
Return value of the main() function
Read return values from your program
echo $?
immediately right after your program executionShell’s short cut branch
Boolean OR (||) – Evaluate until a condition is true
$ ./return 0 || echo 'A' $ ./return 1 || echo 'B'
Boolean AND (&&) – Evaluate until a condition is not false
$ ./return 0 && echo 'C' $ ./return 1 && echo 'D'
Handle program options
參數包含程式名稱本身
#include <unistd.h> int getopt(int argc, char * const argv[], const char *optstring); extern char *optarg; extern int optind, opterr, optopt; /*Return: option now if OK, -1 if no more options, Colon (:) or question mark (?) if Invalid option encountered*/ #include <getopt.h> int getopt_long(int argc, char * const argv[], const char *optstring, const struct option *longopts, int *longindex); int getopt_long_only(int argc, char * const argv[], const char *optstring, const struct option *longopts, int *longindex); struct option { const char *name; int has_arg; int *flag; int val; };
UNIX time representations
struct timeval { long tv_sec; // seconds long tv_usec; // microseconds };
相關函式
#include<time.h> time_t time(time_t *t); int gettimeofday(struct timeval *tv, struct timezone *tz); clock_t clock(void);