
Unix/Linux编程实践教程
薛离子
假如我年少有为不自卑
展开
-
第3章 目录与文件属性:编写ls
/* * ls1.c * purpose list contents of directory or directories * action if no args, use . else list files in args */#include <stdio.h>#include <sys/types.h>#include <dirent.h>void do_ls(char [])原创 2016-12-14 18:57:20 · 277 阅读 · 0 评论 -
第1章 Unix系统编程概述
初窥Unix系统编程本书通过以下3个步骤来学习。 1. 分析程序 首先分析现有的程序,了解它的功能及实现原理 2. 学习系统调用 看程序都用到哪些系统调用,以及每个系统调用的功能和使用方法。 3. 编程实现 利用学到的原理和系统调用,自己编程实现原来程序所实现的功能。以上3步可以通过下面3个问题来实现: * 它能做什么? * 它是如何实现的? * 能不能自己编写一个?原创 2016-12-14 17:23:18 · 301 阅读 · 0 评论 -
第2章 用户、文件操作与联机帮助:编写who命令
/* * who1.c - a first version of the who program * open, read UTMP file, and show results */#include <stdio.h>#include <utmp.h>#include <fcntl.h>#include <unistd.h>#define SHOWHOST原创 2016-12-14 18:54:09 · 337 阅读 · 0 评论 -
第14章 线程机制:并发函数的使用
/* hello_single.c - a single threaded hello world program */#include <stdio.h>#define NUM 5main(){ void print_msg(char *); print_msg("hello"); print_msg("world\n");}void print_msg(char *m)原创 2016-12-14 19:16:25 · 368 阅读 · 0 评论 -
第12章 连接和协议:编写Web服务器
/* * webserv.c - a minimal web server (version 0.2) * usage: ws portnumber * features: supports the GET command only * runs in the current directory * forks a new ch原创 2016-12-14 19:14:40 · 1033 阅读 · 0 评论 -
第11章 连接到近端或远端的进程:服务器与Socket(套接字)
/* * timeserv.c a socket - based time of day server */#include <stdio.h>#include <unistd.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <netdb.h>#include <time原创 2016-12-14 19:11:01 · 411 阅读 · 0 评论 -
第8章 进程和程序:编写命令解释器sh
/* * prompting shell version 1 * Prompts for the command and its arguments. * Builds the argument vector for the call to execvp. * Uses execvp(), and never returns. */#include <stdio.h>#include <原创 2016-12-14 19:08:48 · 311 阅读 · 0 评论 -
第7章 事件驱动编程:编写一个视频游戏
/* * hello.c * purpose show the minimal calls needed to use curses * outline initialize, draw stuff, wait for input, quit */#include <stdio.h>#include <curses.h>main(){ initscr();原创 2016-12-14 19:02:50 · 526 阅读 · 0 评论 -
第4章 文件系统:编写pwd
/* * spwd.c: a simplified version of pwd * * starts in current directory an recursively * climbs up to root of filesystem, prints top part * then prints current part * * uses readdir() to get in原创 2016-12-14 18:58:53 · 328 阅读 · 0 评论 -
第14章 线程机制:并发函数的使用--多线程Web服务器
/* twebserv.c - a threaded minimal web server (version 0.2) * usage : tws portnumber * features : supports the GET command only * runs in the current directory * creates a thread原创 2017-02-21 10:55:06 · 352 阅读 · 0 评论