|
Home | Switchboard | Unix Administration | Red Hat | TCP/IP Networks | Neoliberalism | Toxic Managers |
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and bastardization of classic Unix |
|
|
fxr.watson.org sys-kern-syscalls.master
Wikipedia
System Calls -- slides
mail() {
struct rec { char name[20];
int number;
struct rec *next; }
struct rec *a; /* declare the pointer */
a = (struct rec *) malloc(sizeof(struct rec)); /* get the memory */
a-> = (struct rec *) malloc(sizeof(struct rec)); /*get another one*/
scanf("%s %d", a->, &(a->));
.
free(a); /* release the fist node and loose the second */
}
-->
mail( ) {
FILE *fp, *fopen(); char c;
system("ls -l > tmp"); /* invoking bourne shell */
fp = fopen("tmp", "r");
while ( (c = getc(fp)) != EOF)) putchar(c);
fclose(fp);
}
-->
main( ) {
FILE *infp, *outfp, *popen( ); int c;
infp = popen("ls -l", "r"); /* equivelant to ls -l | thisprogram */
outfp = popen("mail qli", "w");
while ( ( c = getc(infp)) != EOF) fprintf(outfp, "%c", c);
pclose(infp);
pclose(outfp);
}
-->
.
if ( (pid == fork( )) != 0 ) {
printf("I am the parent process\n");
other stuff
wait(&status);
}
else {
printf("I am the child process\n");
. other child process code
}
#include <.h>
main( ) {
.
signal(SIGINT, handler(SIGINT));
/* call hander() if SIGINT arrives */
kill -HUP pid Many system daemons catch this signal and reinitialize themselves.
..
signal(SIGALRM, handletimeout());
..
alarm(20);
.
void handletimeout() {
. }
#include <.h>
#include </signal.h>
#define TIMEOUT 10
static jmp_buf jbuf;
main(int argc, char argv[ ]) {
FILE *fp;
int ecode;
if ( ( fp = fopen( argv[1], "r") == NULL){
perror("ca't open file"); exit(1); }
while (1) {
if (setjmp(jbuf)) == TIMEOUT ) {
printf("Timeout\n"); ecode=0; break;}
else {
signal(SIGALRM, wentoff);
alarm(10);
printf(Enter ID number:");
if (scanf("%d%*c", &id) == EOF) {
ecode = 0; break; }
alarm(0); /* cancel alarm */
if (fseek(fp,id*sizeof(cust), 0)
==NULL) {
perror("can't seek");ecode=1;break;
} else if ( fread((char *) &cust,
sizeof(cust), 1, fp) ! = 1) {
perror("can't read");ecode=1;break;}
print_info(cust);
}} /* if, while */
} /* main() */
wentoff(int signal) {
printf("Timeout has occured\n");
longjmp(jbuf, TIMEOUT);
}
Program one.c :
char *argv[ ]={"two", "abc", "123", '\0'};
char *env[]={"X=100", "Y=200", '\0'};
mail() {
printf("Running one\n");
if (execve("/usr/home/qli/two", argv, env) <= 0 ) {
perror("Can't execl"); }
}
Program two.c :
main(argv, argv)
int argc; char *argv[]; {
char *getenv( ); int i;
printf("Running two\n");
for (I=0; I< I++) printf("%s\n", argv[i]);
printf("%s, %s, %s, %s\n", getenv("X") getenv("Y"), getenv("HOME"), getenv("PWD")); }
%two # running two from shell
Running two
two
(null), (null), /usr/home/qli, /usr/home/qli
%one # running one from shell
Running one
Running two
two
abc
123
100, 200, (null), (null)
#define Read 0
#define Write 1
#define STDIN 0
#define STDOUT 1
main ( ) {
FILE *fpt, *fpw;
int pfd[2]; /* pipe */
pipe(pfd);
if ((pid=fork()) != 0) { /* parent proc */
close(STDOUT);
dup(pfd([Write]);
close(pfd[Write]);
close(pfd[Read]);
.. some code, maybe execl();
} else { /* child process */
close(STDIN);
dup(pfd([Read]);
close(ptd[Read]);
close(pfd[Write]);
. some code, maybe execl();
} /* if */
} /* main */
#include <.h>
#define ERROR -1
main() {
FILE *fdopen(), *fr, *fw;
int pid, pfd[2];
int i, n;
pipe(pfd);
if ((pid=fork()) == ERROR) {
printf("Can't fork\n"); exit(1); }
else if (pid != 0) { /* dad process */
fw = fdopen(pfd[1], "w");
for (i=1; i<=10; i++)
fprintf(fw, "%d\n", i);
fclose(fw);
exit(0);
} else
{ /* son process */
fr = fdopen(pfd[0], "r");
for (i=10; i? i++) {
fscanf(fr, "%d", &n);
printf("In son process: %d\n", n);
}
fclose(fr);
exit(0);
} /* if else */
} /* main */
-->
The following tutorial describes various common methods for reading and writing files and directories on a Unix system. Part of the information is common C knowledge, and is repeated here for completeness. Other information is Unix-specific, although DOS programmers will find some of it similar to what they saw in various DOS compilers. If you are a proficient C programmer, and know everything about the standard I/O functions, its buffering operations, and know functions such as
fseek()
orfread()
, you may skip the standard C library I/O functions section. If in doubt, at least skim through this section, to catch up on things you might not be familiar with, and at least look at the standard C library examples.This document is copyright (c) 1998-2002 by guy keren.
The material in this document is provided AS IS, without any expressed or implied warranty, or claim of fitness for a particular purpose. Neither the author nor any contributers shell be liable for any damages incured directly or indirectly by using the material contained in this document.
permission to copy this document (electronically or on paper, for personal or organization internal use) or publish it on-line is hereby granted, provided that the document is copied as-is, this copyright notice is preserved, and a link to the original document is written in the document's body, or in the page linking to the copy of this document.
Permission to make translations of this document is also granted, under these terms - assuming the translation preserves the meaning of the text, the copyright notice is preserved as-is, and a link to the original document is written in the document's body, or in the page linking to the copy of this document.
For any questions about the document and its license, please contact the author.
|
A rarity - a great computer
book., April 24, 2001
Preface 1. Introduction (a "whirlwind tour of Unix") 2. Unix Standardization and Implementations 3. File I/O 4. Files and Directories 5. Standard I/O Library 6. System Data Files and Information 7. The Environment of a Unix Process 8. Process Control 9. Process Relationships 10. Signals 11. Terminal I/O 12. Advanced I/O 13. Daemon Processes 14. Interprocess Communication 15. Advanced Interprocess Communication 16. A Database Library 17. Communicating with a PostScript Printer 18. A Modem Dialer 19. Pseudo Terminals Appendices A. Function Prototypes B. Miscellaneous Source Code (all source code is available for download) C. Solutions to Selected Exercises Bibliography Index The first thing to understand about the book is that while it can be used as just a reference work (the index is wonderful), it really is a book you can and should read. Even if you think you know a lot of this stuff, you can be surprised at what you can still learn. What makes the book so much more useful than just a collection of man-page print-outs (that dreary and painfully common form of UNIX "book") is the method of presentation. Stevens' basic atom of organization is the function call. For each call (or minor variations on a single call), he provides the C prototype, and then, in text, explains what the function does, what it's arguments are for, and then typically provides a small C program that demonstrates it in action, which he then explains. These function-level building blocks are arranged into related sets, each of which is a chapter in the book. Each chapter has a wrapper that consists of an introduction explaining some basic concepts and history of the functions described in that chapter, and some review exercises at the end. The chapters themselves are arranged so that the earlier chapters describe the basic functions, and the later chapters describe the more difficult functions. Every chapter both teaches the reader something of immediate use in writing code (even the introduction has sample programs), as well as preparing him for the more difficult subjects that lie ahead. Now for the caveats. Stevens absolutely assumes that you know how to program in C and that you know how to use Unix development tools (or at least that you have some other source from which to learn them). This is not the book to learn how to use C or particular shells, editors, compilers, linkers, or debuggers. Similarly, new Unix variants, such as Linux and MacOS X, receive no specific mention here at all (though the book is invaluable for both). Also, there is no discussion of the various GUI interfaces offered on many current Unix systems - for those, some other book will necessary. One other thing worth mentioning is the cost of the book. Don't be put off by it - Stevens' book has been justifying that cost for a lot of readers for a lot of years. In closing, I've been a developer for many years and have owned many computer books. I recommend very few of them, but can't recommend this one highly enough. It is one of the few books I've had that routinely lies open beside me when I work. In addition to my personal recommendation, you might look not only at all the positive reviews for this book, but also at the reviews for "competitive" books and notice how often they refer you back to this one. This book is the standard by which other UNIX programming books are measured, and so far, it has not been surpassed |
Using Unix System Calls by M. Rochkind, W.Toomey
Programming in C -- David Marshall 1994 Contains a lot of useful info on system calls
UNIX and C
Unix Seventh Edition Manual This is a classic. See vol1/man2.bun - system calls for historical information that may help to understand Unix kernel evolution.
Syscall specifications of Linux - Table of Contents by Louis-Dominique Dubeau.
[Beej's Guide] A fork() primer -- From Beej's Guide to Unix Interprocess Communication
Syscall specifications of Linux - Table of Contents by Louis-Dominique Dubeau.
Tour of the Linux kernel source
Berkeley UNIX System Calls and Interprocess Communication
The Linux Programmer's Guide, version 0.4 by B. Scott Burkett, Sven Goldt, John D. Harper, Sven van der Meer and Matt Welsh, is available in HTML, HTML (tared and gziped), LaTeX source, PDF and PostScript.
http://www.opengroup.org/onlinepubs/7908799/
libc -- GNU C Library - GNU Project - Free Software Foundation (FSF)
Any Unix-like operating system needs a C library: the library which defines the ``system calls'' and other basic facilities such as malloc.
The history of Unix and various standards determine much of the interface of the C library. In general the GNU C library supports the ISO C and POSIX standards. We also try to support the features of popular Unix variants (including BSD and System V) when those do not conflict with the standards. Different compatibility modes (selectable when you compile an application) allow the peaceful coexistence of compatibility support for different varieties of Unix.
FreeCode Free Programming Source Code
UNIX Socket Programming in C -- Programming UNIX Sockets in C - Frequently Asked Questions Created by Vic Metcalfe, Andrew Gierth and other contributers May 21, 1998
W. Richard Stevens home page
Society
Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers : Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism : The Iron Law of Oligarchy : Libertarian Philosophy
Quotes
War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda : SE quotes : Language Design and Programming Quotes : Random IT-related quotes : Somerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose Bierce : Bernard Shaw : Mark Twain Quotes
Bulletin:
Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 : Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law
History:
Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds : Larry Wall : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOS : Programming Languages History : PL/1 : Simula 67 : C : History of GCC development : Scripting Languages : Perl history : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history
Classic books:
The Peter Principle : Parkinson Law : 1984 : The Mythical Man-Month : How to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Haters Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite
Most popular humor pages:
Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor
The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D
Copyright ฉ 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.
This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...
|
You can use PayPal to to buy a cup of coffee for authors of this site |
Disclaimer:
The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.
Last modified: March 12, 2019