The proliferation of different versions of Unix during the 1980s has been tempered by the various international standards that were started during the late 1980s. These include the ANSI standard for the C programming language, the IEEE POSIX family (still being developed), and the X/Open portability guide.
Please refer to http://en.wikipedia.org/wiki/ANSI_C
Please refer to http://en.wikipedia.org/wiki/POSIX
Please refer to http://en.wikipedia.org/wiki/X/Open
Kernal ------>> System Call(POSIX API) ------>> Shell ------>> Application
------>> Libraray Routines ------>> Application
------>> Application
For more vavid diagram, please see the attachment #1.
Header: unistd.h
Constants: STDIN_FILENO, STDOUT_FILENO and STDERR_FILENO
Functions: open, read, write, lseek, and close
Header: stdio.h
Constants: stdin, stdout, stderr, EOF
Functions: printf, getc and putc
#include "apue.h" #include <sys/wait.h> int main(void) { char buf[MAXLINE]; /* from apue.h */ pid_t pid; int status; printf("%% "); /* print prompt (printf requires %% to print %) */ while (fgets(buf, MAXLINE, stdin) != NULL) { if (buf[strlen(buf) - 1] == "\n") buf[strlen(buf) - 1] = 0; /* replace newline with null */ if ((pid = fork()) < 0) { /*Fork starts a new process, the new process is a copy of the current process. Then fork returns the non-negative process ID of the new child process to the parent, and returns 0 to the child.*/ err_sys("fork error"); } else if (pid == 0) { /* child */ /*The child process gets the pid == 0, so goes here.*/ execlp(buf, buf, (char *)0); err_ret("couldn't execute: %s", buf); /*If execlp runs successfully, it exit the process. If not, it goes here.*/ exit(127); } /* parent */ /*The parent process gets the pid > 0, so goes here.*/ if ((pid = waitpid(pid, &status, 0)) < 0) err_sys("waitpid error"); printf("%% "); } exit(0); }
This function maps errnum, which is typically the errno value, into an error message string and returns a pointer to the string.
It outputs the string pointed to by msg, followed by a colon and a space, followed by the error message corresponding to the value of errno, followed by a newline.
int main(int argc, char *argv[]) { fprintf(stderr, "EACCES: %s\n", strerror(EACCES)); errno = ENOENT; perror(argv[0]); exit(0); }
int signal(SIGINT, sig_int)
SIGINT: Interupt Signal by Ctrl + C/Delete.
void sig_int(int signo)
sig_int is a function to receive the signal.
The clock time, sometimes called wall clock time, is the amount of time the process takes to run, and its value depends on the number of other processes being run on the system.
The user CPU time is the CPU time attributed to user instructions.
The system CPU time is the CPU time attributed to the kernel when it executes on behalf of the process.
For more vavid diagram, please see the attachment #2.