├── README.md ├── SUMMARY.md ├── apue ├── apue.3e │ ├── DISCLAIMER │ ├── Make.defines.freebsd │ ├── Make.defines.linux │ ├── Make.defines.macos │ ├── Make.defines.solaris │ ├── Make.libapue.inc │ ├── Makefile │ ├── README │ ├── advio │ │ ├── Makefile │ │ ├── deadlock │ │ ├── deadlock.c │ │ ├── fixup.awk │ │ ├── lockfile.c │ │ ├── mandatory │ │ ├── mandatory.c │ │ ├── mcopy2 │ │ ├── mcopy2.c │ │ ├── nonblockw │ │ ├── nonblockw.c │ │ ├── readn.c │ │ ├── rot13a │ │ ├── rot13a.c │ │ ├── rot13c2 │ │ ├── rot13c2.c │ │ ├── rot13c2.c.in │ │ ├── writen.c │ │ └── xlate │ ├── daemons │ │ ├── Makefile │ │ ├── init.c │ │ ├── reread.c │ │ ├── reread2.c │ │ └── single.c │ ├── datafiles │ │ ├── Makefile │ │ ├── getpwnam.c │ │ ├── strftime │ │ └── strftime.c │ ├── db │ │ ├── Makefile │ │ ├── apue_db.h │ │ ├── db.c │ │ ├── t4 │ │ └── t4.c │ ├── environ │ │ ├── Makefile │ │ ├── cmd1.c │ │ ├── cmd2.c │ │ ├── doatexit │ │ ├── doatexit.c │ │ ├── echoarg │ │ ├── echoarg.c │ │ ├── getrlimit │ │ ├── getrlimit.c │ │ ├── hello1 │ │ ├── hello1.c │ │ ├── opendata.c │ │ ├── scope.c │ │ ├── testjmp │ │ └── testjmp.c │ ├── exercises │ │ ├── Makefile │ │ ├── asyncsocket.c │ │ ├── bo │ │ ├── bo.c │ │ ├── fifo1 │ │ ├── fifo1.c │ │ ├── fmemopen.c │ │ ├── getlogin │ │ ├── getlogin.c │ │ ├── getpw44bsd.c │ │ ├── getpwsvr4 │ │ ├── getpwsvr4.c │ │ ├── goodexit │ │ ├── goodexit.c │ │ ├── longpath │ │ ├── longpath.c │ │ ├── openmax.c │ │ ├── pendlock │ │ ├── pendlock.c │ │ ├── pollmsg2.c │ │ ├── prtime │ │ ├── prtime.c │ │ ├── sizepipe │ │ ├── sizepipe.c │ │ ├── sleep.c │ │ ├── sleepus_poll.c │ │ ├── sleepus_select.c │ │ ├── vfork3 │ │ ├── vfork3.c │ │ ├── zombie │ │ └── zombie.c │ ├── figlinks │ │ ├── fig1.10 │ │ ├── fig1.3 │ │ ├── fig1.4 │ │ ├── fig1.5 │ │ ├── fig1.6 │ │ ├── fig1.7 │ │ ├── fig1.8 │ │ ├── fig1.9 │ │ ├── fig10.10 │ │ ├── fig10.11 │ │ ├── fig10.12 │ │ ├── fig10.14 │ │ ├── fig10.15 │ │ ├── fig10.18 │ │ ├── fig10.19 │ │ ├── fig10.2 │ │ ├── fig10.20 │ │ ├── fig10.22 │ │ ├── fig10.23 │ │ ├── fig10.24 │ │ ├── fig10.25 │ │ ├── fig10.26 │ │ ├── fig10.28 │ │ ├── fig10.29 │ │ ├── fig10.31 │ │ ├── fig10.5 │ │ ├── fig10.6 │ │ ├── fig10.7 │ │ ├── fig10.8 │ │ ├── fig10.9 │ │ ├── fig11.10 │ │ ├── fig11.11 │ │ ├── fig11.12 │ │ ├── fig11.14 │ │ ├── fig11.15 │ │ ├── fig11.16 │ │ ├── fig11.2 │ │ ├── fig11.3 │ │ ├── fig11.4 │ │ ├── fig11.5 │ │ ├── fig12.11 │ │ ├── fig12.12 │ │ ├── fig12.13 │ │ ├── fig12.16 │ │ ├── fig12.17 │ │ ├── fig12.4 │ │ ├── fig12.8 │ │ ├── fig13.1 │ │ ├── fig13.6 │ │ ├── fig13.7 │ │ ├── fig13.8 │ │ ├── fig13.9 │ │ ├── fig14.1 │ │ ├── fig14.12 │ │ ├── fig14.20 │ │ ├── fig14.21 │ │ ├── fig14.24 │ │ ├── fig14.27 │ │ ├── fig14.5 │ │ ├── fig14.6 │ │ ├── fig14.7 │ │ ├── fig14.9 │ │ ├── fig15.11 │ │ ├── fig15.12 │ │ ├── fig15.14 │ │ ├── fig15.15 │ │ ├── fig15.17 │ │ ├── fig15.18 │ │ ├── fig15.19 │ │ ├── fig15.31 │ │ ├── fig15.33 │ │ ├── fig15.35 │ │ ├── fig15.5 │ │ ├── fig15.6 │ │ ├── fig15.7 │ │ ├── fig16.10 │ │ ├── fig16.11 │ │ ├── fig16.12 │ │ ├── fig16.16 │ │ ├── fig16.17 │ │ ├── fig16.18 │ │ ├── fig16.19 │ │ ├── fig16.20 │ │ ├── fig16.22 │ │ ├── fig16.9 │ │ ├── fig17.10 │ │ ├── fig17.12 │ │ ├── fig17.13 │ │ ├── fig17.14 │ │ ├── fig17.15 │ │ ├── fig17.16 │ │ ├── fig17.17 │ │ ├── fig17.18 │ │ ├── fig17.19 │ │ ├── fig17.2 │ │ ├── fig17.20 │ │ ├── fig17.21 │ │ ├── fig17.22 │ │ ├── fig17.23 │ │ ├── fig17.24 │ │ ├── fig17.25 │ │ ├── fig17.26 │ │ ├── fig17.27 │ │ ├── fig17.28 │ │ ├── fig17.29 │ │ ├── fig17.3 │ │ ├── fig17.30 │ │ ├── fig17.31 │ │ ├── fig17.4 │ │ ├── fig17.5 │ │ ├── fig17.8 │ │ ├── fig17.9 │ │ ├── fig18.10 │ │ ├── fig18.11 │ │ ├── fig18.12 │ │ ├── fig18.13 │ │ ├── fig18.14 │ │ ├── fig18.15 │ │ ├── fig18.16 │ │ ├── fig18.17 │ │ ├── fig18.18 │ │ ├── fig18.20 │ │ ├── fig18.21 │ │ ├── fig18.22 │ │ ├── fig19.10 │ │ ├── fig19.11 │ │ ├── fig19.12 │ │ ├── fig19.16 │ │ ├── fig19.9 │ │ ├── fig2.13 │ │ ├── fig2.14 │ │ ├── fig2.16 │ │ ├── fig2.17 │ │ ├── fig20.3 │ │ ├── fig3.1 │ │ ├── fig3.11 │ │ ├── fig3.12 │ │ ├── fig3.2 │ │ ├── fig3.5 │ │ ├── fig4.12 │ │ ├── fig4.16 │ │ ├── fig4.21 │ │ ├── fig4.22 │ │ ├── fig4.23 │ │ ├── fig4.24 │ │ ├── fig4.25 │ │ ├── fig4.3 │ │ ├── fig4.8 │ │ ├── fig4.9 │ │ ├── fig5.11 │ │ ├── fig5.12 │ │ ├── fig5.13 │ │ ├── fig5.15 │ │ ├── fig5.4 │ │ ├── fig5.5 │ │ ├── fig6.11 │ │ ├── fig6.2 │ │ ├── fig7.1 │ │ ├── fig7.11 │ │ ├── fig7.13 │ │ ├── fig7.14 │ │ ├── fig7.16 │ │ ├── fig7.3 │ │ ├── fig7.4 │ │ ├── fig7.9 │ │ ├── fig8.1 │ │ ├── fig8.12 │ │ ├── fig8.13 │ │ ├── fig8.16 │ │ ├── fig8.17 │ │ ├── fig8.20 │ │ ├── fig8.21 │ │ ├── fig8.22 │ │ ├── fig8.23 │ │ ├── fig8.24 │ │ ├── fig8.25 │ │ ├── fig8.28 │ │ ├── fig8.29 │ │ ├── fig8.3 │ │ ├── fig8.30 │ │ ├── fig8.31 │ │ ├── fig8.5 │ │ ├── fig8.6 │ │ ├── fig8.8 │ │ ├── fig9.12 │ │ ├── figB.1 │ │ ├── figB.3 │ │ ├── figB.4 │ │ ├── figC.1 │ │ ├── figC.10 │ │ ├── figC.12 │ │ ├── figC.13 │ │ ├── figC.14 │ │ ├── figC.15 │ │ ├── figC.16 │ │ ├── figC.17 │ │ ├── figC.18 │ │ ├── figC.20 │ │ ├── figC.22 │ │ ├── figC.23 │ │ ├── figC.24 │ │ ├── figC.3 │ │ ├── figC.4 │ │ ├── figC.5 │ │ ├── figC.6 │ │ ├── figC.7 │ │ └── figC.8 │ ├── filedir │ │ ├── Makefile │ │ ├── access │ │ ├── access.c │ │ ├── cdpwd │ │ ├── cdpwd.c │ │ ├── changemod │ │ ├── changemod.c │ │ ├── devrdev │ │ ├── devrdev.c │ │ ├── filetype │ │ ├── filetype.c │ │ ├── ftw8 │ │ ├── ftw8.c │ │ ├── mycd │ │ ├── mycd.c │ │ ├── umask │ │ ├── umask.c │ │ ├── unlink │ │ ├── unlink.c │ │ ├── zap │ │ └── zap.c │ ├── fileio │ │ ├── Makefile │ │ ├── fileflags │ │ ├── fileflags.c │ │ ├── hole │ │ ├── hole.c │ │ ├── mycat │ │ ├── mycat.c │ │ ├── seek │ │ ├── seek.c │ │ └── setfl.c │ ├── include │ │ └── apue.h │ ├── intro │ │ ├── Makefile │ │ ├── getcputc │ │ ├── getcputc.c │ │ ├── hello │ │ ├── hello.c │ │ ├── ls1 │ │ ├── ls1.c │ │ ├── mycat │ │ ├── mycat.c │ │ ├── shell1 │ │ ├── shell1.c │ │ ├── shell2 │ │ ├── shell2.c │ │ ├── testerror │ │ ├── testerror.c │ │ ├── uidgid │ │ └── uidgid.c │ ├── ipc1 │ │ ├── Makefile │ │ ├── add2 │ │ ├── add2.c │ │ ├── add2stdio │ │ ├── add2stdio.c │ │ ├── devzero │ │ ├── devzero.c │ │ ├── myuclc │ │ ├── myuclc.c │ │ ├── pipe1 │ │ ├── pipe1.c │ │ ├── pipe2 │ │ ├── pipe2.c │ │ ├── pipe4 │ │ ├── pipe4.c │ │ ├── popen.c │ │ ├── popen1 │ │ ├── popen1.c │ │ ├── popen2 │ │ ├── popen2.c │ │ ├── slock.c │ │ ├── slock.h │ │ ├── tellwait.c │ │ ├── tshm │ │ └── tshm.c │ ├── ipc2 │ │ ├── Makefile │ │ ├── bindunix │ │ ├── bindunix.c │ │ ├── open.fe │ │ │ ├── Makefile │ │ │ ├── main.c │ │ │ ├── open.c │ │ │ ├── open.h │ │ │ └── openclient │ │ ├── open │ │ │ ├── Makefile │ │ │ ├── main.c │ │ │ ├── open.c │ │ │ ├── open.h │ │ │ └── openclient │ │ ├── opend.fe │ │ │ ├── Makefile │ │ │ ├── cliargs.c │ │ │ ├── main.c │ │ │ ├── opend │ │ │ ├── opend.h │ │ │ └── request.c │ │ ├── opend │ │ │ ├── Makefile │ │ │ ├── cliargs.c │ │ │ ├── client.c │ │ │ ├── loop.poll.c │ │ │ ├── loop.select.c │ │ │ ├── main.c │ │ │ ├── opend.h │ │ │ ├── opend.poll │ │ │ ├── opend.select │ │ │ └── request.c │ │ ├── pollmsg │ │ ├── pollmsg.c │ │ ├── recvfd2.c │ │ ├── sendfd2.c │ │ ├── sendmsg │ │ └── sendmsg.c │ ├── lib │ │ ├── Makefile │ │ ├── Orecvfd.c │ │ ├── bufargs.c │ │ ├── cliconn.c │ │ ├── clrfl.c │ │ ├── daemonize.c │ │ ├── error.c │ │ ├── errorlog.c │ │ ├── lockreg.c │ │ ├── locktest.c │ │ ├── nspipe.c │ │ ├── openmax.c │ │ ├── pathalloc.c │ │ ├── popen.c │ │ ├── prexit.c │ │ ├── prmask.c │ │ ├── ptyfork.c │ │ ├── ptyopen.c │ │ ├── readn.c │ │ ├── recvfd.c │ │ ├── semaph.c │ │ ├── senderr.c │ │ ├── sendfd.c │ │ ├── servaccept.c │ │ ├── servlisten.c │ │ ├── setfd.c │ │ ├── setfl.c │ │ ├── signal.c │ │ ├── signalintr.c │ │ ├── sleep.c │ │ ├── sleepus.c │ │ ├── spipe.c │ │ ├── strerror.c │ │ ├── tellwait.c │ │ ├── ttymodes.c │ │ └── writen.c │ ├── printer │ │ ├── Makefile │ │ ├── ipp.h │ │ ├── print │ │ ├── print.c │ │ ├── print.h │ │ ├── printd │ │ ├── printd.c │ │ └── util.c │ ├── proc │ │ ├── Makefile │ │ ├── awkexample │ │ ├── echoall │ │ ├── echoall.c │ │ ├── exec1 │ │ ├── exec1.c │ │ ├── exec2 │ │ ├── exec2.c │ │ ├── fork1 │ │ ├── fork1.c │ │ ├── fork2 │ │ ├── fork2.c │ │ ├── nice │ │ ├── nice.c │ │ ├── pracct │ │ ├── pracct.c │ │ ├── pruids │ │ ├── pruids.c │ │ ├── system.c │ │ ├── systest1 │ │ ├── systest1.c │ │ ├── systest3 │ │ ├── systest3.c │ │ ├── tellwait1 │ │ ├── tellwait1.c │ │ ├── tellwait2 │ │ ├── tellwait2.c │ │ ├── test1 │ │ ├── test1.c │ │ ├── times1 │ │ ├── times1.c │ │ ├── vfork1 │ │ ├── vfork1.c │ │ ├── wait1 │ │ └── wait1.c │ ├── pty │ │ ├── Makefile │ │ ├── driver.c │ │ ├── loop.c │ │ ├── main.c │ │ └── pty │ ├── relation │ │ ├── Makefile │ │ ├── orphan3 │ │ └── orphan3.c │ ├── signals │ │ ├── Makefile │ │ ├── abort.c │ │ ├── child │ │ ├── child.c │ │ ├── critical │ │ ├── critical.c │ │ ├── mask │ │ ├── mask.c │ │ ├── read1 │ │ ├── read1.c │ │ ├── read2 │ │ ├── read2.c │ │ ├── reenter │ │ ├── reenter.c │ │ ├── setops.c │ │ ├── sigtstp │ │ ├── sigtstp.c │ │ ├── sigusr │ │ ├── sigusr.c │ │ ├── sleep1.c │ │ ├── sleep2.c │ │ ├── suspend1 │ │ ├── suspend1.c │ │ ├── suspend2 │ │ ├── suspend2.c │ │ ├── system.c │ │ ├── systest2 │ │ ├── systest2.c │ │ ├── tsleep2 │ │ └── tsleep2.c │ ├── sockets │ │ ├── clconn.c │ │ ├── clconn2.c │ │ ├── findsvc │ │ ├── findsvc.c │ │ ├── initsrv1.c │ │ ├── initsrv2.c │ │ ├── makefile │ │ ├── ruptime │ │ ├── ruptime-dg │ │ ├── ruptime-dg.c │ │ ├── ruptime.c │ │ ├── ruptimed │ │ ├── ruptimed-dg │ │ ├── ruptimed-dg.c │ │ ├── ruptimed-fd │ │ ├── ruptimed-fd.c │ │ └── ruptimed.c │ ├── standards │ │ ├── Makefile │ │ ├── conf │ │ ├── conf.c │ │ ├── conf.c.modified │ │ ├── makeconf.awk │ │ ├── makeopt.awk │ │ ├── options │ │ ├── options.c │ │ ├── pathconf-lim.sym │ │ ├── pathconf-opt.sym │ │ ├── pathconf.sym │ │ ├── pathopt.sym │ │ ├── sysconf-lim.sym │ │ ├── sysconf-opt.sym │ │ ├── sysconf.sym │ │ └── sysopt.sym │ ├── stdio │ │ ├── Makefile │ │ ├── buf │ │ ├── buf.c │ │ ├── fgetsfputs │ │ ├── fgetsfputs.c │ │ ├── getcharbug │ │ ├── getcharbug.c │ │ ├── getcputc │ │ ├── getcputc.c │ │ ├── memstr │ │ ├── memstr.c │ │ ├── mkstemp │ │ ├── mkstemp.c │ │ ├── tempfiles │ │ └── tempfiles.c │ ├── systype.sh │ ├── termios │ │ ├── Makefile │ │ ├── csize │ │ ├── csize.c │ │ ├── ctermid.c │ │ ├── getpass.c │ │ ├── isatty.c │ │ ├── settty │ │ ├── settty.c │ │ ├── t_getpass │ │ ├── t_getpass.c │ │ ├── t_isatty │ │ ├── t_isatty.c │ │ ├── t_raw │ │ ├── t_raw.c │ │ ├── t_ttyname │ │ ├── t_ttyname.c │ │ ├── ttyname.c │ │ ├── winch │ │ └── winch.c │ ├── threadctl │ │ ├── Makefile │ │ ├── atfork │ │ ├── atfork.c │ │ ├── detach.c │ │ ├── getenv1.c │ │ ├── getenv2.c │ │ ├── getenv3.c │ │ ├── suspend │ │ ├── suspend.c │ │ └── timeout.c │ └── threads │ │ ├── Makefile │ │ ├── badexit2 │ │ ├── badexit2.c │ │ ├── barrier │ │ ├── barrier.c │ │ ├── cleanup │ │ ├── cleanup.c │ │ ├── condvar.c │ │ ├── exitstatus │ │ ├── exitstatus.c │ │ ├── maketimeout.c │ │ ├── mutex1.c │ │ ├── mutex2.c │ │ ├── mutex3.c │ │ ├── rwlock.c │ │ ├── threadid │ │ ├── threadid.c │ │ ├── timedlock │ │ └── timedlock.c └── src.3e.tar.gz ├── code ├── 05UnixunitStdIo │ ├── 01MyEffectIo │ ├── 01MyEffectIo.c │ ├── 02MyeffectioRdWr │ ├── 02MyeffectioRdWr.c │ ├── 03MyIoStdio │ ├── 03MyIoStdio.c │ ├── 04Mytempfile │ ├── 04Mytempfile.c │ ├── 05Mymsktemp │ ├── 05Mymsktemp.c │ ├── 065-14Memorystream │ ├── 065-14Memorystream.c │ ├── std.err │ └── std.out ├── 06UnixunitsystemdateInfo │ ├── 016-2Mygetpwnam.c │ ├── 02Mygettime │ ├── 02Mygettime.c │ ├── 03Myuname │ ├── 03Myuname.c │ ├── 06.2Myshadow │ └── 06.2Myshadow.c ├── 07UnixunitForkEnv │ ├── 01Myhelloworld │ ├── 01Myhelloworld.c │ ├── 02Myexit │ ├── 02Myexit.c │ ├── 03Myecho │ ├── 03Myecho.c │ ├── 047-10Myjmp │ ├── 047-10Myjmp.c │ ├── 057-11externMyjmp │ ├── 057-11externMyjmp.c │ ├── 067-13Mytestjmp │ ├── 067-13Mytestjmp.c │ └── a.out ├── 08ForkContral │ ├── 01.out │ ├── 018-1MyforkGetid │ ├── 018-1MyforkGetid.c │ ├── 028-3Myvfork │ ├── 028-3Myvfork.c │ ├── 03-8_6Mypr_exitstatus │ ├── 03-8_6Mypr_exitstatus.c │ ├── 04-8_8MysolveZombieFork │ ├── 04-8_8MysolveZombieFork.c │ ├── 05-8-12MyIpc │ ├── 05-8-12MyIpc.c │ ├── 06-8_13MyextendIPC │ ├── 06-8_13MyextendIPC.c │ ├── 08-8_16Myexec │ ├── 08-8_16Myexec.c │ ├── 09-8-17Myechoall │ ├── 09-8-17Myechoall.c │ ├── 11-8_22MySystem.c │ ├── 12-8_23MytestSystem │ ├── 12-8_23MytestSystem.c │ ├── 13-8-24MycommandSystem │ ├── 13-8-24MycommandSystem.c │ ├── 14-08_28MyProcessAccount │ ├── 14-08_28MyProcessAccount.c │ ├── 15-08_29MyTestProcessAccount │ ├── 15-08_29MyTestProcessAccount.c │ ├── 16-08_30Mynice │ ├── 16-08_30Mynice.c │ ├── 17-08_31MyTmsShell │ ├── 17-08_31MyTmsShell.c │ ├── 18-MyZombieofork │ └── 18-MyZombieofork.c ├── 09Forkresulation │ ├── 01-09_12MyOrphanProcess │ ├── 01-09_12MyOrphanProcess.c │ ├── 9.1practice.md │ ├── a.out │ ├── main.c │ ├── makefile │ └── temp.foo ├── 10Signal │ ├── 01MyexternSignal │ ├── 01MyexternSignal.c │ ├── 02-1MyTrafficcontral │ ├── 02-1MyTrafficcontral.c │ ├── 02MyTrafficContral.c │ ├── 03-10_2Mysignal │ ├── 03-10_2Mysignal.c │ ├── 10-10_23MySigsuspendWait │ ├── 10-10_23MySigsuspendWait.c │ ├── 11-10_24MyTELLSignal.c │ ├── 12-10_25Myabort.c │ ├── 13-10_26MysystemEd │ ├── 13-10_26MysystemEd.c │ ├── 14-10_28MySystem.c │ ├── 15-10_31MySignalContral │ ├── 15-10_31MySignalContral.c │ ├── 2-10_5MySIGALARMsignal │ ├── 2-10_5MySIGALARMsignal.c │ ├── 3-10MySIGCHLD │ ├── 3-10MySIGCHLD.c │ ├── 3-10_6MySIGCLD │ ├── 3-10_6MySIGCLD.c │ ├── 4-10.7.8.9MySIGALRM │ ├── 5-10_10Myalarm │ ├── 5-10_10Myalarm.c │ ├── 6-10MyalarmLongjmp │ ├── 6-10MyalarmLongjmp.c │ ├── 7-10.11MySignalSet │ ├── 7-10.11MySignalSet.c │ ├── 8-10_20.19.18MySetjmp │ ├── 8-10_20.19.18MySetjmp.c │ ├── 9-10-22MySigsuspend │ ├── 9-10-22MySigsuspend.c │ ├── changeSystem.md │ ├── log │ ├── temp.foo │ └── trafficContral.txt ├── 11UnixUnitThread │ ├── 01-11_2MyThreadCreate │ ├── 01-11_2MyThreadCreate.c │ ├── 10-11_15MyValueMUtex.c │ ├── 11-11_16MyTasksPthreadSort │ ├── 11-11_16MyTasksPthreadSort.c │ ├── 2-11_3MyThreadExit │ ├── 2-11_3MyThreadExit.c │ ├── 3-11_4MyPthread_exitwrong │ ├── 3-11_4MyPthread_exitwrong.c │ ├── 4-11_5MyPthreadCleanProgram │ ├── 4-11_5MyPthreadCleanProgram.c │ ├── 5-11_10MyPthreadMutex_t.c │ ├── 6-11_11MyTwoMutex.c │ ├── 7-11_12MyUpdateTwoMutex.c │ ├── 8-11_13_Mypthread_mutex_timedlock │ ├── 8-11_13_Mypthread_mutex_timedlock.c │ └── 9-11_14MyReadWriteLock.c ├── 12UnixUnitThreadAttr │ ├── .02-12_4MySpecStatusCreatePthread.c.swo │ ├── .02-12_4MySpecStatusCreatePthread.c.swp │ ├── 01MyThreadSide │ ├── 01MyThreadSide.c │ ├── 02-12_4MySpecStatusCreatePthread │ ├── 02-12_4MySpecStatusCreatePthread.c │ ├── 06-2_16MymutexSignalPthread │ ├── 06-2_16MymutexSignalPthread.c │ ├── 07-12_17MyPthread_atfork │ ├── 07-12_17MyPthread_atfork.c │ └── 7-12_17.txt ├── 13UnixUnitDaemonFork │ ├── 01-13_1MyinitDaemonFork │ ├── 01-13_1MyinitDaemonFork.c │ ├── 02-13_6MySigleDaemon.c │ ├── 03-13_7MyDaemonSecond │ ├── 03-13_7MyDaemonSecond.c │ ├── 04-13_8MyPthreadGetSignalConf │ ├── 04-13_8MyPthreadGetSignalConf.c │ ├── 05-13_9Mysetckoexec.c │ └── readme.md ├── 14UnixUnitAdvancedIO │ ├── 01-14_1MyNoBlockIo │ ├── 01-14_1MyNoBlockIo.c │ ├── 01stderr.file │ ├── 01temp.file │ ├── 0214_5MyAccReleaseLock.c │ ├── 04-14_7MyDiedLock │ ├── 04-14_7MyDiedLock.c │ ├── 05-14_9Myloocfile.c │ ├── 06-.lock │ ├── 06-14_12MyConfirmLockSystem │ ├── 06-14_12MyConfirmLockSystem.c │ ├── 07-14_20MyTransFile │ ├── 07-14_20MyTransFile.c │ ├── 07_testone.md │ ├── 07_testtwo.md │ ├── 08-14_21MyAsynchronousIO │ ├── 08-14_21MyAsynchronousIO.c │ ├── 08-final.md │ ├── 08-test.md │ ├── 09-14_24MyReadnWriten.c │ ├── 10-14_27MyMemory-mappedIO │ ├── 10-14_27MyMemory-mappedIO.c │ ├── 10-Test.txt │ ├── 10-TestFinal.txt │ ├── 14_Homework01 │ ├── 14_Homework01.c │ ├── _testone.md │ ├── lockfile │ ├── readme.md │ └── templock ├── 15UnixUnitIPC │ ├── 01-15_5MyParent2ChildForkIPC │ ├── 01-15_5MyParent2ChildForkIPC.c │ ├── 02-15_6MyPipeDeparPage │ ├── 02-15_6MyPipeDeparPage.c │ ├── 03-15_7MyPipeTellWait.c │ ├── 04-15_6MyPopenOveriedCp │ ├── 04-15_6MyPopenOveriedCp.c │ ├── 05-15_12MyFunctionPopen-Pclose.c │ ├── 06-15_14MySimpleCp │ ├── 06-15_14MySimpleCp.c │ ├── 07-15_15MyExternPopenGetFileToExec │ ├── 07-15_15MyExternPopenGetFileToExec.c │ ├── 08-15_17MyCoprocess │ ├── 08-15_17MyCoprocess.c │ ├── 09-15_18MyCoprocessApplication │ ├── 09-15_18MyCoprocessApplication.c │ ├── 10-15_19MyStdIoCoprocessadd.c │ ├── 11-15_31MyPrintMemAddr │ ├── 11-15_31MyPrintMemAddr.c │ ├── 12-15_33MyIPCSharedMemUse_dev_zero │ ├── 12-15_33MyIPCSharedMemUse_dev_zero.c │ ├── 13-15_35MySemaphore.c │ ├── readme.md │ └── slock.h ├── 16UnixUnitInterIPCsocket │ ├── 01-16_9MyGetaddrinfoHowToUse │ ├── 01-16_9MyGetaddrinfoHowToUse.c │ ├── 02@03-16_10@11MyConnect_retry.c │ ├── 04-16_12MyInitSocketFunction.c │ ├── 05-16_16MyGetSeverTime │ ├── 05-16_16MyGetSeverTime.c │ ├── 06-_17MyPostClientTime │ ├── 06-_17MyPostClientTime.c │ ├── 07-16_MyExternSever.c │ └── readme.md ├── GetEnv ├── GetEnv.cpp ├── Myselectexample ├── Myselectexample.c ├── OperatorEnv ├── OperatorEnv.cpp ├── SerityTest.txt ├── UnixUnit01 │ ├── Dirls.c │ ├── Dirls.o │ ├── MyCopy.c │ ├── MyCopy.o │ ├── MyPrintuserid.c │ ├── MyPrintuserid.o │ ├── MyShell.c │ ├── MyShell.o │ ├── MyShell01singal.c │ ├── MyShell01singal.o │ ├── Myerror.c │ ├── Myerror.o │ ├── Myfock.c │ ├── Myfork.o │ ├── Myio.c │ ├── Myio.data │ ├── Myio.o │ └── Test*++.c ├── UnixUnitIO03 │ ├── MyCreatemptyio │ ├── MyCreatemptyio.c │ ├── MyCreatio.c │ ├── MyEffectio │ ├── MyEffectio.c │ ├── MyFileioAnnoce │ ├── MyFileioAnnoce.c │ ├── MyStdio │ ├── MyStdio.c │ ├── Myoffsetio │ ├── Myoffsetio.c │ ├── file │ └── myfile.txt ├── UnixUnitIO04 │ ├── 10Mydev │ ├── 10Mydev.c │ ├── MyFileDirTraverse │ ├── MyFileDirTraverse.c │ ├── MyJudgementIo │ ├── MyJudgementIo.c │ ├── Myaccessio │ ├── Myaccessio.c │ ├── Mychdir08 │ ├── Mychdir08.c │ ├── Mychmodio │ ├── Mychmodio.c │ ├── Myfutimes │ ├── Myfutimes.c │ ├── Mygetcwd09 │ ├── Mygetcwd09.c │ ├── Mylink │ ├── Mylink.c │ ├── Myumask │ ├── Myumask.c │ ├── bar │ ├── foo │ └── testln │ │ └── a ├── apue.h ├── epolldir │ ├── Client │ ├── Client1 │ ├── Sever │ ├── client.cpp │ ├── epollClient.cpp │ ├── epollHeader.h │ └── epollSever.cpp ├── error.c └── fork.c ├── docs ├── APUE环境搭建 │ ├── APUE环境搭建.md │ └── image │ │ ├── 1530766056596.png │ │ ├── 1530766270952.png │ │ ├── 1530766324344.png │ │ └── 1530766411506.png ├── 第10章-信号 │ └── 第10章-信号.md ├── 第11章-线程 │ └── 第11章-线程.md ├── 第12章-线程控制 │ └── 第12章-线程控制.md ├── 第13章-守护进程 │ └── 第13章-守护进程.md ├── 第14章-高级IO │ └── 第14章-高级IO.md ├── 第15章-进程间通信 │ └── 第15章-进程间通信.md ├── 第16章-网络IPC套接字 │ └── 第16章-网络IPC套接字.md ├── 第17章-高级进程间通信 │ └── 第17章-高级进程间通信.md ├── 第18章-终端IO │ └── 第18章-终端IO.md ├── 第19章-伪终端 │ └── 第19章-伪终端.md ├── 第1章-UNIX基础知识 │ └── 第1章-UNIX基础知识.md ├── 第20章-数据库函数 │ └── 第20章-数据库函数.md ├── 第21章-与网络打印机通信 │ └── 第21章-与网络打印机通信.md ├── 第2章-UNIX标准及实现 │ └── 第2章-UNIX标准及实现.md ├── 第3章-文件IO │ └── 第3章-文件IO.md ├── 第4章-文件和目录 │ └── 第4章-文件和目录.md ├── 第5章-标准IO库 │ └── 第5章-标准IO库.md ├── 第6章-系统数据文件和信息 │ └── 第6章-系统数据文件和信息.md ├── 第7章-进程环境 │ └── 第7章-进程环境.md ├── 第8章-进程控制 │ └── 第8章-进程控制.md └── 第9章-进程关系 │ └── 第9章-进程关系.md └── image └── 1533726645683.png /apue/apue.3e/Make.defines.freebsd: -------------------------------------------------------------------------------- 1 | # Common make definitions, customized for each platform 2 | 3 | # Definitions required in all program directories to compile and link 4 | # C programs using gcc. 5 | 6 | CC=gcc 7 | COMPILE.c=$(CC) $(CFLAGS) $(CPPFLAGS) -c 8 | LINK.c=$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) 9 | LDFLAGS= 10 | LDDIR=-L$(ROOT)/lib 11 | LDLIBS=$(LDDIR) -lapue $(EXTRALIBS) 12 | CFLAGS=-ansi -I$(ROOT)/include -Wall -DBSD -D__BSD_VISIBLE $(EXTRA) 13 | RANLIB=ranlib 14 | AR=ar 15 | AWK=awk 16 | LIBAPUE=$(ROOT)/lib/libapue.a 17 | 18 | # Common temp files to delete from each directory. 19 | TEMPFILES=core core.* *.o temp.* *.out 20 | -------------------------------------------------------------------------------- /apue/apue.3e/Make.defines.linux: -------------------------------------------------------------------------------- 1 | # Common make definitions, customized for each platform 2 | 3 | # Definitions required in all program directories to compile and link 4 | # C programs using gcc. 5 | 6 | CC=gcc 7 | COMPILE.c=$(CC) $(CFLAGS) $(CPPFLAGS) -c 8 | LINK.c=$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) 9 | LDFLAGS= 10 | LDDIR=-L$(ROOT)/lib 11 | LDLIBS=$(LDDIR) -lapue $(EXTRALIBS) 12 | CFLAGS=-ansi -I$(ROOT)/include -Wall -DLINUX -D_GNU_SOURCE $(EXTRA) 13 | RANLIB=echo 14 | AR=ar 15 | AWK=awk 16 | LIBAPUE=$(ROOT)/lib/libapue.a 17 | 18 | # Common temp files to delete from each directory. 19 | TEMPFILES=core core.* *.o temp.* *.out 20 | -------------------------------------------------------------------------------- /apue/apue.3e/Make.defines.macos: -------------------------------------------------------------------------------- 1 | # Common make definitions, customized for each platform 2 | 3 | # Definitions required in all program directories to compile and link 4 | # C programs using gcc. 5 | 6 | CC=gcc 7 | COMPILE.c=$(CC) $(CFLAGS) $(CPPFLAGS) -c 8 | LINK.c=$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) 9 | LDFLAGS= 10 | LDDIR=-L$(ROOT)/lib 11 | LDLIBS=$(LDDIR) -lapue $(EXTRALIBS) 12 | CFLAGS=-ansi -I$(ROOT)/include -Wall -DMACOS -D_DARWIN_C_SOURCE $(EXTRA) 13 | RANLIB=ranlib 14 | AR=ar 15 | AWK=awk 16 | LIBAPUE=$(ROOT)/lib/libapue.a 17 | 18 | # Common temp files to delete from each directory. 19 | TEMPFILES=core core.* *.o temp.* *.out 20 | -------------------------------------------------------------------------------- /apue/apue.3e/Make.libapue.inc: -------------------------------------------------------------------------------- 1 | $(LIBAPUE): 2 | (cd $(ROOT)/lib && $(MAKE)) 3 | -------------------------------------------------------------------------------- /apue/apue.3e/Makefile: -------------------------------------------------------------------------------- 1 | DIRS = lib intro sockets advio daemons datafiles db environ \ 2 | fileio filedir ipc1 ipc2 proc pty relation signals standards \ 3 | stdio termios threadctl threads printer exercises 4 | 5 | all: 6 | for i in $(DIRS); do \ 7 | (cd $$i && echo "making $$i" && $(MAKE) ) || exit 1; \ 8 | done 9 | 10 | clean: 11 | for i in $(DIRS); do \ 12 | (cd $$i && echo "cleaning $$i" && $(MAKE) clean) || exit 1; \ 13 | done 14 | -------------------------------------------------------------------------------- /apue/apue.3e/README: -------------------------------------------------------------------------------- 1 | Read the file called DISCLAIMER. 2 | 3 | On Freebsd, type "gmake". 4 | On other platforms, type "make" (as long as this is gnu make). 5 | 6 | For FAQs, updated source code, and the lost chapter, see http://www.apuebook.com. 7 | Please direct questions, suggestions, and bug reports to sar@apuebook.com. 8 | 9 | Steve Rago 10 | January 2013 11 | -------------------------------------------------------------------------------- /apue/apue.3e/advio/deadlock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/advio/deadlock -------------------------------------------------------------------------------- /apue/apue.3e/advio/fixup.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/awk -f 2 | BEGIN { 3 | ready = 0 4 | } 5 | /^translate/ { 6 | ready = 1 7 | next 8 | } 9 | /^{/ { 10 | next 11 | } 12 | /^}/ { 13 | ready = 0 14 | next 15 | } 16 | { 17 | if (ready) 18 | print $0 19 | } 20 | -------------------------------------------------------------------------------- /apue/apue.3e/advio/lockfile.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | lockfile(int fd) 6 | { 7 | struct flock fl; 8 | 9 | fl.l_type = F_WRLCK; 10 | fl.l_start = 0; 11 | fl.l_whence = SEEK_SET; 12 | fl.l_len = 0; 13 | return(fcntl(fd, F_SETLK, &fl)); 14 | } 15 | -------------------------------------------------------------------------------- /apue/apue.3e/advio/mandatory: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/advio/mandatory -------------------------------------------------------------------------------- /apue/apue.3e/advio/mcopy2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/advio/mcopy2 -------------------------------------------------------------------------------- /apue/apue.3e/advio/nonblockw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/advio/nonblockw -------------------------------------------------------------------------------- /apue/apue.3e/advio/readn.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | ssize_t /* Read "n" bytes from a descriptor */ 4 | readn(int fd, void *ptr, size_t n) 5 | { 6 | size_t nleft; 7 | ssize_t nread; 8 | 9 | nleft = n; 10 | while (nleft > 0) { 11 | if ((nread = read(fd, ptr, nleft)) < 0) { 12 | if (nleft == n) 13 | return(-1); /* error, return -1 */ 14 | else 15 | break; /* error, return amount read so far */ 16 | } else if (nread == 0) { 17 | break; /* EOF */ 18 | } 19 | nleft -= nread; 20 | ptr += nread; 21 | } 22 | return(n - nleft); /* return >= 0 */ 23 | } 24 | -------------------------------------------------------------------------------- /apue/apue.3e/advio/rot13a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/advio/rot13a -------------------------------------------------------------------------------- /apue/apue.3e/advio/rot13c2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/advio/rot13c2 -------------------------------------------------------------------------------- /apue/apue.3e/advio/writen.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | ssize_t /* Write "n" bytes to a descriptor */ 4 | writen(int fd, const void *ptr, size_t n) 5 | { 6 | size_t nleft; 7 | ssize_t nwritten; 8 | 9 | nleft = n; 10 | while (nleft > 0) { 11 | if ((nwritten = write(fd, ptr, nleft)) < 0) { 12 | if (nleft == n) 13 | return(-1); /* error, return -1 */ 14 | else 15 | break; /* error, return amount written so far */ 16 | } else if (nwritten == 0) { 17 | break; 18 | } 19 | nleft -= nwritten; 20 | ptr += nwritten; 21 | } 22 | return(n - nleft); /* return >= 0 */ 23 | } 24 | -------------------------------------------------------------------------------- /apue/apue.3e/advio/xlate: -------------------------------------------------------------------------------- 1 | if (isalpha(c)) { 2 | if (c >= 'n') 3 | c -= 13; 4 | else if (c >= 'a') 5 | c += 13; 6 | else if (c >= 'N') 7 | c -= 13; 8 | else 9 | c += 13; 10 | } 11 | return(c); 12 | -------------------------------------------------------------------------------- /apue/apue.3e/daemons/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | all: init.o reread.o reread2.o single.o 6 | 7 | clean: 8 | rm -f $(TEMPFILES) *.o 9 | -------------------------------------------------------------------------------- /apue/apue.3e/datafiles/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | PROGS = strftime 6 | 7 | all: $(PROGS) getpwnam.o 8 | 9 | %: %.c $(LIBAPUE) 10 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 11 | 12 | clean: 13 | rm -f $(PROGS) $(TEMPFILES) *.o 14 | 15 | include $(ROOT)/Make.libapue.inc 16 | -------------------------------------------------------------------------------- /apue/apue.3e/datafiles/getpwnam.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct passwd * 6 | getpwnam(const char *name) 7 | { 8 | struct passwd *ptr; 9 | 10 | setpwent(); 11 | while ((ptr = getpwent()) != NULL) 12 | if (strcmp(name, ptr->pw_name) == 0) 13 | break; /* found a match */ 14 | endpwent(); 15 | return(ptr); /* ptr is NULL if no match found */ 16 | } 17 | -------------------------------------------------------------------------------- /apue/apue.3e/datafiles/strftime: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/datafiles/strftime -------------------------------------------------------------------------------- /apue/apue.3e/datafiles/strftime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int 6 | main(void) 7 | { 8 | time_t t; 9 | struct tm *tmp; 10 | char buf1[16]; 11 | char buf2[64]; 12 | 13 | time(&t); 14 | tmp = localtime(&t); 15 | if (strftime(buf1, 16, "time and date: %r, %a %b %d, %Y", tmp) == 0) 16 | printf("buffer length 16 is too small\n"); 17 | else 18 | printf("%s\n", buf1); 19 | if (strftime(buf2, 64, "time and date: %r, %a %b %d, %Y", tmp) == 0) 20 | printf("buffer length 64 is too small\n"); 21 | else 22 | printf("%s\n", buf2); 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /apue/apue.3e/db/t4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/db/t4 -------------------------------------------------------------------------------- /apue/apue.3e/db/t4.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include "apue_db.h" 3 | #include 4 | 5 | int 6 | main(void) 7 | { 8 | DBHANDLE db; 9 | 10 | if ((db = db_open("db4", O_RDWR | O_CREAT | O_TRUNC, 11 | FILE_MODE)) == NULL) 12 | err_sys("db_open error"); 13 | 14 | if (db_store(db, "Alpha", "data1", DB_INSERT) != 0) 15 | err_quit("db_store error for alpha"); 16 | if (db_store(db, "beta", "Data for beta", DB_INSERT) != 0) 17 | err_quit("db_store error for beta"); 18 | if (db_store(db, "gamma", "record3", DB_INSERT) != 0) 19 | err_quit("db_store error for gamma"); 20 | 21 | db_close(db); 22 | exit(0); 23 | } 24 | -------------------------------------------------------------------------------- /apue/apue.3e/environ/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | PROGS = doatexit echoarg getrlimit hello1 testjmp 6 | 7 | all: $(PROGS) opendata.o scope.o 8 | 9 | %: %.c $(LIBAPUE) 10 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 11 | 12 | clean: 13 | rm -f $(PROGS) $(TEMPFILES) *.o 14 | 15 | include $(ROOT)/Make.libapue.inc 16 | -------------------------------------------------------------------------------- /apue/apue.3e/environ/cmd2.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define TOK_ADD 5 5 | 6 | jmp_buf jmpbuffer; 7 | 8 | int 9 | main(void) 10 | { 11 | char line[MAXLINE]; 12 | 13 | if (setjmp(jmpbuffer) != 0) 14 | printf("error"); 15 | while (fgets(line, MAXLINE, stdin) != NULL) 16 | do_line(line); 17 | exit(0); 18 | } 19 | 20 | . . . 21 | 22 | void 23 | cmd_add(void) 24 | { 25 | int token; 26 | 27 | token = get_token(); 28 | if (token < 0) /* an error has occurred */ 29 | longjmp(jmpbuffer, 1); 30 | /* rest of processing for this command */ 31 | } 32 | -------------------------------------------------------------------------------- /apue/apue.3e/environ/doatexit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/environ/doatexit -------------------------------------------------------------------------------- /apue/apue.3e/environ/doatexit.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | static void my_exit1(void); 4 | static void my_exit2(void); 5 | 6 | int 7 | main(void) 8 | { 9 | if (atexit(my_exit2) != 0) 10 | err_sys("can't register my_exit2"); 11 | 12 | if (atexit(my_exit1) != 0) 13 | err_sys("can't register my_exit1"); 14 | if (atexit(my_exit1) != 0) 15 | err_sys("can't register my_exit1"); 16 | 17 | printf("main is done\n"); 18 | return(0); 19 | } 20 | 21 | static void 22 | my_exit1(void) 23 | { 24 | printf("first exit handler\n"); 25 | } 26 | 27 | static void 28 | my_exit2(void) 29 | { 30 | printf("second exit handler\n"); 31 | } 32 | -------------------------------------------------------------------------------- /apue/apue.3e/environ/echoarg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/environ/echoarg -------------------------------------------------------------------------------- /apue/apue.3e/environ/echoarg.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(int argc, char *argv[]) 5 | { 6 | int i; 7 | 8 | for (i = 0; i < argc; i++) /* echo all command-line args */ 9 | printf("argv[%d]: %s\n", i, argv[i]); 10 | exit(0); 11 | } 12 | -------------------------------------------------------------------------------- /apue/apue.3e/environ/getrlimit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/environ/getrlimit -------------------------------------------------------------------------------- /apue/apue.3e/environ/hello1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/environ/hello1 -------------------------------------------------------------------------------- /apue/apue.3e/environ/hello1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | main() 4 | { 5 | printf("hello, world\n"); 6 | } 7 | -------------------------------------------------------------------------------- /apue/apue.3e/environ/opendata.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | FILE * 4 | open_data(void) 5 | { 6 | FILE *fp; 7 | char databuf[BUFSIZ]; /* setvbuf makes this the stdio buffer */ 8 | 9 | if ((fp = fopen("datafile", "r")) == NULL) 10 | return(NULL); 11 | if (setvbuf(fp, databuf, _IOLBF, BUFSIZ) != 0) 12 | return(NULL); 13 | return(fp); /* error */ 14 | } 15 | -------------------------------------------------------------------------------- /apue/apue.3e/environ/scope.c: -------------------------------------------------------------------------------- 1 | int 2 | f1(int val) 3 | { 4 | int num = 0; 5 | int *ptr = # 6 | 7 | if (val == 0) { 8 | int val; 9 | 10 | val = 5; 11 | ptr = &val; 12 | } 13 | return(*ptr + 1); 14 | } 15 | -------------------------------------------------------------------------------- /apue/apue.3e/environ/testjmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/environ/testjmp -------------------------------------------------------------------------------- /apue/apue.3e/exercises/asyncsocket.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #if defined(BSD) || defined(MACOS) || defined(SOLARIS) 7 | #include 8 | #endif 9 | 10 | int 11 | setasync(int sockfd) 12 | { 13 | int n; 14 | 15 | if (fcntl(sockfd, F_SETOWN, getpid()) < 0) 16 | return(-1); 17 | n = 1; 18 | if (ioctl(sockfd, FIOASYNC, &n) < 0) 19 | return(-1); 20 | return(0); 21 | } 22 | 23 | int 24 | clrasync(int sockfd) 25 | { 26 | int n; 27 | 28 | n = 0; 29 | if (ioctl(sockfd, FIOASYNC, &n) < 0) 30 | return(-1); 31 | return(0); 32 | } 33 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/bo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/exercises/bo -------------------------------------------------------------------------------- /apue/apue.3e/exercises/bo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int 6 | main(void) 7 | { 8 | uint32_t i = 0x04030201; 9 | unsigned char *cp = (unsigned char *)&i; 10 | 11 | if (*cp == 1) 12 | printf("little-endian\n"); 13 | else if (*cp == 4) 14 | printf("big-endian\n"); 15 | else 16 | printf("who knows?\n"); 17 | exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/fifo1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/exercises/fifo1 -------------------------------------------------------------------------------- /apue/apue.3e/exercises/fifo1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define FIFO "temp.fifo" 5 | 6 | int 7 | main(void) 8 | { 9 | int fdread, fdwrite; 10 | 11 | unlink(FIFO); 12 | if (mkfifo(FIFO, FILE_MODE) < 0) 13 | err_sys("mkfifo error"); 14 | if ((fdread = open(FIFO, O_RDONLY | O_NONBLOCK)) < 0) 15 | err_sys("open error for reading"); 16 | if ((fdwrite = open(FIFO, O_WRONLY)) < 0) 17 | err_sys("open error for writing"); 18 | clr_fl(fdread, O_NONBLOCK); 19 | exit(0); 20 | } 21 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/getlogin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/exercises/getlogin -------------------------------------------------------------------------------- /apue/apue.3e/exercises/getlogin.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | FILE *fp; 7 | char *p; 8 | 9 | daemonize("getlog"); 10 | p = getlogin(); 11 | fp = fopen("/tmp/getlog.out", "w"); 12 | if (fp != NULL) { 13 | if (p == NULL) 14 | fprintf(fp, "no login name\n"); 15 | else 16 | fprintf(fp, "login name: %s\n", p); 17 | } 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/getpw44bsd.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) /* FreeBSD/Mac OS X version */ 6 | { 7 | struct passwd *ptr; 8 | 9 | if ((ptr = getpwnam("sar")) == NULL) 10 | err_sys("getpwnam error"); 11 | printf("pw_passwd = %s\n", ptr->pw_passwd == NULL || 12 | ptr->pw_passwd[0] == 0 ? "(null)" : ptr->pw_passwd); 13 | exit(0); 14 | } 15 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/getpwsvr4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/exercises/getpwsvr4 -------------------------------------------------------------------------------- /apue/apue.3e/exercises/getpwsvr4.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) /* Linux/Solaris version */ 6 | { 7 | struct spwd *ptr; 8 | 9 | if ((ptr = getspnam("sar")) == NULL) 10 | err_sys("getspnam error"); 11 | printf("sp_pwdp = %s\n", ptr->sp_pwdp == NULL || 12 | ptr->sp_pwdp[0] == 0 ? "(null)" : ptr->sp_pwdp); 13 | exit(0); 14 | } 15 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/goodexit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/exercises/goodexit -------------------------------------------------------------------------------- /apue/apue.3e/exercises/longpath: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/exercises/longpath -------------------------------------------------------------------------------- /apue/apue.3e/exercises/openmax.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | #include 4 | 5 | #define OPEN_MAX_GUESS 256 6 | 7 | long 8 | open_max(void) 9 | { 10 | long openmax; 11 | struct rlimit rl; 12 | 13 | if ((openmax = sysconf(_SC_OPEN_MAX)) < 0 || 14 | openmax == LONG_MAX) { 15 | if (getrlimit(RLIMIT_NOFILE, &rl) < 0) 16 | err_sys("can't get file limit"); 17 | if (rl.rlim_max == RLIM_INFINITY) 18 | openmax = OPEN_MAX_GUESS; 19 | else 20 | openmax = rl.rlim_max; 21 | } 22 | return(openmax); 23 | } 24 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/pendlock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/exercises/pendlock -------------------------------------------------------------------------------- /apue/apue.3e/exercises/prtime: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/exercises/prtime -------------------------------------------------------------------------------- /apue/apue.3e/exercises/prtime.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | time_t caltime; 8 | struct tm *tm; 9 | char line[MAXLINE]; 10 | 11 | if ((caltime = time(NULL)) == -1) 12 | err_sys("time error"); 13 | if ((tm = localtime(&caltime)) == NULL) 14 | err_sys("localtime error"); 15 | if (strftime(line, MAXLINE, "%a %b %d %X %Z %Y\n", tm) == 0) 16 | err_sys("strftime error"); 17 | fputs(line, stdout); 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/sizepipe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/exercises/sizepipe -------------------------------------------------------------------------------- /apue/apue.3e/exercises/sizepipe.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | int i, n; 8 | int fd[2]; 9 | 10 | if (pipe(fd) < 0) 11 | err_sys("pipe error"); 12 | set_fl(fd[1], O_NONBLOCK); 13 | 14 | /* write 1 byte at a time until pipe is full */ 15 | for (n = 0; ; n++) { 16 | if ((i = write(fd[1], "a", 1)) != 1) { 17 | printf("write ret %d, ", i); 18 | break; 19 | } 20 | } 21 | printf("pipe capacity = %d\n", n); 22 | exit(0); 23 | } 24 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/sleep.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | unsigned 6 | sleep(unsigned seconds) 7 | { 8 | int n; 9 | unsigned slept; 10 | time_t start, end; 11 | struct timeval tv; 12 | 13 | tv.tv_sec = seconds; 14 | tv.tv_usec = 0; 15 | time(&start); 16 | n = select(0, NULL, NULL, NULL, &tv); 17 | if (n == 0) 18 | return(0); 19 | time(&end); 20 | slept = end - start; 21 | if (slept >= seconds) 22 | return(0); 23 | return(seconds - slept); 24 | } 25 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/sleepus_poll.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void 4 | sleep_us(unsigned int nusecs) 5 | { 6 | struct pollfd dummy; 7 | int timeout; 8 | 9 | if ((timeout = nusecs / 1000) <= 0) 10 | timeout = 1; 11 | poll(&dummy, 0, timeout); 12 | } 13 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/sleepus_select.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | void 5 | sleep_us(unsigned int nusecs) 6 | { 7 | struct timeval tval; 8 | 9 | tval.tv_sec = nusecs / 1000000; 10 | tval.tv_usec = nusecs % 1000000; 11 | select(0, NULL, NULL, NULL, &tval); 12 | } 13 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/vfork3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/exercises/vfork3 -------------------------------------------------------------------------------- /apue/apue.3e/exercises/vfork3.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | static void f1(void), f2(void); 4 | 5 | int 6 | main(void) 7 | { 8 | f1(); 9 | f2(); 10 | _exit(0); 11 | } 12 | 13 | static void 14 | f1(void) 15 | { 16 | pid_t pid; 17 | 18 | if ((pid = vfork()) < 0) 19 | err_sys("vfork error"); 20 | /* child and parent both return */ 21 | } 22 | 23 | static void 24 | f2(void) 25 | { 26 | char buf[1000]; /* automatic variables */ 27 | int i; 28 | 29 | for (i = 0; i < sizeof(buf); i++) 30 | buf[i] = 0; 31 | } 32 | -------------------------------------------------------------------------------- /apue/apue.3e/exercises/zombie: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/exercises/zombie -------------------------------------------------------------------------------- /apue/apue.3e/exercises/zombie.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | #ifdef SOLARIS 4 | #define PSCMD "ps -a -o pid,ppid,s,tty,comm" 5 | #else 6 | #define PSCMD "ps -o pid,ppid,state,tty,command" 7 | #endif 8 | 9 | int 10 | main(void) 11 | { 12 | pid_t pid; 13 | 14 | if ((pid = fork()) < 0) 15 | err_sys("fork error"); 16 | else if (pid == 0) /* child */ 17 | exit(0); 18 | 19 | /* parent */ 20 | sleep(4); 21 | system(PSCMD); 22 | 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig1.10: -------------------------------------------------------------------------------- 1 | ../intro/shell2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig1.3: -------------------------------------------------------------------------------- 1 | ../intro/ls1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig1.4: -------------------------------------------------------------------------------- 1 | ../intro/mycat.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig1.5: -------------------------------------------------------------------------------- 1 | ../intro/getcputc.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig1.6: -------------------------------------------------------------------------------- 1 | ../intro/hello.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig1.7: -------------------------------------------------------------------------------- 1 | ../intro/shell1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig1.8: -------------------------------------------------------------------------------- 1 | ../intro/testerror.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig1.9: -------------------------------------------------------------------------------- 1 | ../intro/uidgid.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.10: -------------------------------------------------------------------------------- 1 | ../signals/read1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.11: -------------------------------------------------------------------------------- 1 | ../signals/read2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.12: -------------------------------------------------------------------------------- 1 | ../signals/setops.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.14: -------------------------------------------------------------------------------- 1 | ../lib/prmask.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.15: -------------------------------------------------------------------------------- 1 | ../signals/critical.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.18: -------------------------------------------------------------------------------- 1 | ../lib/signal.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.19: -------------------------------------------------------------------------------- 1 | ../lib/signalintr.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.2: -------------------------------------------------------------------------------- 1 | ../signals/sigusr.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.20: -------------------------------------------------------------------------------- 1 | ../signals/mask.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.22: -------------------------------------------------------------------------------- 1 | ../signals/suspend1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.23: -------------------------------------------------------------------------------- 1 | ../signals/suspend2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.24: -------------------------------------------------------------------------------- 1 | ../lib/tellwait.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.25: -------------------------------------------------------------------------------- 1 | ../signals/abort.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.26: -------------------------------------------------------------------------------- 1 | ../signals/systest2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.28: -------------------------------------------------------------------------------- 1 | ../signals/system.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.29: -------------------------------------------------------------------------------- 1 | ../lib/sleep.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.31: -------------------------------------------------------------------------------- 1 | ../signals/sigtstp.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.5: -------------------------------------------------------------------------------- 1 | ../signals/reenter.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.6: -------------------------------------------------------------------------------- 1 | ../signals/child.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.7: -------------------------------------------------------------------------------- 1 | ../signals/sleep1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.8: -------------------------------------------------------------------------------- 1 | ../signals/sleep2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig10.9: -------------------------------------------------------------------------------- 1 | ../signals/tsleep2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.10: -------------------------------------------------------------------------------- 1 | ../threads/mutex1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.11: -------------------------------------------------------------------------------- 1 | ../threads/mutex2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.12: -------------------------------------------------------------------------------- 1 | ../threads/mutex3.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.14: -------------------------------------------------------------------------------- 1 | ../threads/rwlock.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.15: -------------------------------------------------------------------------------- 1 | ../threads/condvar.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.16: -------------------------------------------------------------------------------- 1 | ../threads/barrier.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.2: -------------------------------------------------------------------------------- 1 | ../threads/threadid.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.3: -------------------------------------------------------------------------------- 1 | ../threads/exitstatus.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.4: -------------------------------------------------------------------------------- 1 | ../threads/badexit2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig11.5: -------------------------------------------------------------------------------- 1 | ../threads/cleanup.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig12.11: -------------------------------------------------------------------------------- 1 | ../threadctl/getenv1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig12.12: -------------------------------------------------------------------------------- 1 | ../threadctl/getenv2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig12.13: -------------------------------------------------------------------------------- 1 | ../threadctl/getenv3.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig12.16: -------------------------------------------------------------------------------- 1 | ../threadctl/suspend.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig12.17: -------------------------------------------------------------------------------- 1 | ../threadctl/atfork.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig12.4: -------------------------------------------------------------------------------- 1 | ../threadctl/detach.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig12.8: -------------------------------------------------------------------------------- 1 | ../threadctl/timeout.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig13.1: -------------------------------------------------------------------------------- 1 | ../daemons/init.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig13.6: -------------------------------------------------------------------------------- 1 | ../daemons/single.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig13.7: -------------------------------------------------------------------------------- 1 | ../daemons/reread.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig13.8: -------------------------------------------------------------------------------- 1 | ../daemons/reread2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig13.9: -------------------------------------------------------------------------------- 1 | ../lib/setfd.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.1: -------------------------------------------------------------------------------- 1 | ../advio/nonblockw.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.12: -------------------------------------------------------------------------------- 1 | ../advio/mandatory.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.20: -------------------------------------------------------------------------------- 1 | ../advio/rot13a.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.21: -------------------------------------------------------------------------------- 1 | ../advio/rot13c2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.24: -------------------------------------------------------------------------------- 1 | ../advio/writen.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.27: -------------------------------------------------------------------------------- 1 | ../advio/mcopy2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.5: -------------------------------------------------------------------------------- 1 | ../lib/lockreg.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.6: -------------------------------------------------------------------------------- 1 | ../lib/locktest.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.7: -------------------------------------------------------------------------------- 1 | ../advio/deadlock.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig14.9: -------------------------------------------------------------------------------- 1 | ../advio/lockfile.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.11: -------------------------------------------------------------------------------- 1 | ../ipc1/popen2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.12: -------------------------------------------------------------------------------- 1 | ../ipc1/popen.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.14: -------------------------------------------------------------------------------- 1 | ../ipc1/myuclc.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.15: -------------------------------------------------------------------------------- 1 | ../ipc1/popen1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.17: -------------------------------------------------------------------------------- 1 | ../ipc1/add2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.18: -------------------------------------------------------------------------------- 1 | ../ipc1/pipe4.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.19: -------------------------------------------------------------------------------- 1 | ../ipc1/add2stdio.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.31: -------------------------------------------------------------------------------- 1 | ../ipc1/tshm.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.33: -------------------------------------------------------------------------------- 1 | ../ipc1/devzero.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.35: -------------------------------------------------------------------------------- 1 | ../ipc1/slock.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.5: -------------------------------------------------------------------------------- 1 | ../ipc1/pipe1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.6: -------------------------------------------------------------------------------- 1 | ../ipc1/pipe2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig15.7: -------------------------------------------------------------------------------- 1 | ../ipc1/tellwait.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.10: -------------------------------------------------------------------------------- 1 | ../sockets/clconn.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.11: -------------------------------------------------------------------------------- 1 | ../sockets/clconn2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.12: -------------------------------------------------------------------------------- 1 | ../sockets/initsrv1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.16: -------------------------------------------------------------------------------- 1 | ../sockets/ruptime.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.17: -------------------------------------------------------------------------------- 1 | ../sockets/ruptimed.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.18: -------------------------------------------------------------------------------- 1 | ../sockets/ruptimed-fd.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.19: -------------------------------------------------------------------------------- 1 | ../sockets/ruptime-dg.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.20: -------------------------------------------------------------------------------- 1 | ../sockets/ruptimed-dg.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.22: -------------------------------------------------------------------------------- 1 | ../sockets/initsrv2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig16.9: -------------------------------------------------------------------------------- 1 | ../sockets/findsvc.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.10: -------------------------------------------------------------------------------- 1 | ../lib/cliconn.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.12: -------------------------------------------------------------------------------- 1 | ../lib/senderr.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.13: -------------------------------------------------------------------------------- 1 | ../lib/sendfd.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.14: -------------------------------------------------------------------------------- 1 | ../lib/recvfd.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.15: -------------------------------------------------------------------------------- 1 | ../ipc2/sendfd2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.16: -------------------------------------------------------------------------------- 1 | ../ipc2/recvfd2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.17: -------------------------------------------------------------------------------- 1 | ../ipc2/open.fe/open.h -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.18: -------------------------------------------------------------------------------- 1 | ../ipc2/open.fe/main.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.19: -------------------------------------------------------------------------------- 1 | ../ipc2/open.fe/open.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.2: -------------------------------------------------------------------------------- 1 | ../lib/spipe.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.20: -------------------------------------------------------------------------------- 1 | ../ipc2/opend.fe/opend.h -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.21: -------------------------------------------------------------------------------- 1 | ../ipc2/opend.fe/main.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.22: -------------------------------------------------------------------------------- 1 | ../ipc2/opend.fe/request.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.23: -------------------------------------------------------------------------------- 1 | ../lib/bufargs.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.24: -------------------------------------------------------------------------------- 1 | ../ipc2/opend.fe/cliargs.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.25: -------------------------------------------------------------------------------- 1 | ../ipc2/open/open.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.26: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/opend.h -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.27: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/client.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.28: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/main.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.29: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/loop.select.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.3: -------------------------------------------------------------------------------- 1 | ../ipc2/pollmsg.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.30: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/loop.poll.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.31: -------------------------------------------------------------------------------- 1 | ../ipc2/opend/request.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.4: -------------------------------------------------------------------------------- 1 | ../ipc2/sendmsg.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.5: -------------------------------------------------------------------------------- 1 | ../ipc2/bindunix.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.8: -------------------------------------------------------------------------------- 1 | ../lib/servlisten.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig17.9: -------------------------------------------------------------------------------- 1 | ../lib/servaccept.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.10: -------------------------------------------------------------------------------- 1 | ../termios/settty.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.11: -------------------------------------------------------------------------------- 1 | ../termios/csize.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.12: -------------------------------------------------------------------------------- 1 | ../termios/ctermid.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.13: -------------------------------------------------------------------------------- 1 | ../termios/isatty.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.14: -------------------------------------------------------------------------------- 1 | ../termios/t_isatty.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.15: -------------------------------------------------------------------------------- 1 | ../termios/ttyname.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.16: -------------------------------------------------------------------------------- 1 | ../termios/t_ttyname.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.17: -------------------------------------------------------------------------------- 1 | ../termios/getpass.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.18: -------------------------------------------------------------------------------- 1 | ../termios/t_getpass.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.20: -------------------------------------------------------------------------------- 1 | ../lib/ttymodes.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.21: -------------------------------------------------------------------------------- 1 | ../termios/t_raw.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig18.22: -------------------------------------------------------------------------------- 1 | ../termios/winch.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig19.10: -------------------------------------------------------------------------------- 1 | ../lib/ptyfork.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig19.11: -------------------------------------------------------------------------------- 1 | ../pty/main.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig19.12: -------------------------------------------------------------------------------- 1 | ../pty/loop.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig19.16: -------------------------------------------------------------------------------- 1 | ../pty/driver.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig19.9: -------------------------------------------------------------------------------- 1 | ../lib/ptyopen.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig2.13: -------------------------------------------------------------------------------- 1 | ../standards/makeconf.awk -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig2.14: -------------------------------------------------------------------------------- 1 | ../standards/conf.c.modified -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig2.16: -------------------------------------------------------------------------------- 1 | ../lib/pathalloc.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig2.17: -------------------------------------------------------------------------------- 1 | ../lib/openmax.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig20.3: -------------------------------------------------------------------------------- 1 | ../db/t4.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig3.1: -------------------------------------------------------------------------------- 1 | ../fileio/seek.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig3.11: -------------------------------------------------------------------------------- 1 | ../fileio/fileflags.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig3.12: -------------------------------------------------------------------------------- 1 | ../fileio/setfl.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig3.2: -------------------------------------------------------------------------------- 1 | ../fileio/hole.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig3.5: -------------------------------------------------------------------------------- 1 | ../fileio/mycat.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.12: -------------------------------------------------------------------------------- 1 | ../filedir/changemod.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.16: -------------------------------------------------------------------------------- 1 | ../filedir/unlink.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.21: -------------------------------------------------------------------------------- 1 | ../filedir/zap.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.22: -------------------------------------------------------------------------------- 1 | ../filedir/ftw8.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.23: -------------------------------------------------------------------------------- 1 | ../filedir/mycd.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.24: -------------------------------------------------------------------------------- 1 | ../filedir/cdpwd.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.25: -------------------------------------------------------------------------------- 1 | ../filedir/devrdev.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.3: -------------------------------------------------------------------------------- 1 | ../filedir/filetype.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.8: -------------------------------------------------------------------------------- 1 | ../filedir/access.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig4.9: -------------------------------------------------------------------------------- 1 | ../filedir/umask.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig5.11: -------------------------------------------------------------------------------- 1 | ../stdio/buf.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig5.12: -------------------------------------------------------------------------------- 1 | ../stdio/tempfiles.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig5.13: -------------------------------------------------------------------------------- 1 | ../stdio/mkstemp.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig5.15: -------------------------------------------------------------------------------- 1 | ../stdio/memstr.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig5.4: -------------------------------------------------------------------------------- 1 | ../stdio/getcputc.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig5.5: -------------------------------------------------------------------------------- 1 | ../stdio/fgetsfputs.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig6.11: -------------------------------------------------------------------------------- 1 | ../datafiles/strftime.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig6.2: -------------------------------------------------------------------------------- 1 | ../datafiles/getpwnam.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig7.1: -------------------------------------------------------------------------------- 1 | ../environ/hello1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig7.11: -------------------------------------------------------------------------------- 1 | ../environ/cmd2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig7.13: -------------------------------------------------------------------------------- 1 | ../environ/testjmp.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig7.14: -------------------------------------------------------------------------------- 1 | ../environ/opendata.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig7.16: -------------------------------------------------------------------------------- 1 | ../environ/getrlimit.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig7.3: -------------------------------------------------------------------------------- 1 | ../environ/doatexit.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig7.4: -------------------------------------------------------------------------------- 1 | ../environ/echoarg.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig7.9: -------------------------------------------------------------------------------- 1 | ../environ/cmd1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.1: -------------------------------------------------------------------------------- 1 | ../proc/fork1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.12: -------------------------------------------------------------------------------- 1 | ../proc/tellwait1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.13: -------------------------------------------------------------------------------- 1 | ../proc/tellwait2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.16: -------------------------------------------------------------------------------- 1 | ../proc/exec1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.17: -------------------------------------------------------------------------------- 1 | ../proc/echoall.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.20: -------------------------------------------------------------------------------- 1 | ../proc/exec2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.21: -------------------------------------------------------------------------------- 1 | ../proc/awkexample -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.22: -------------------------------------------------------------------------------- 1 | ../proc/system.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.23: -------------------------------------------------------------------------------- 1 | ../proc/systest1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.24: -------------------------------------------------------------------------------- 1 | ../proc/systest3.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.25: -------------------------------------------------------------------------------- 1 | ../proc/pruids.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.28: -------------------------------------------------------------------------------- 1 | ../proc/test1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.29: -------------------------------------------------------------------------------- 1 | ../proc/pracct.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.3: -------------------------------------------------------------------------------- 1 | ../proc/vfork1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.30: -------------------------------------------------------------------------------- 1 | ../proc/nice.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.31: -------------------------------------------------------------------------------- 1 | ../proc/times1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.5: -------------------------------------------------------------------------------- 1 | ../lib/prexit.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.6: -------------------------------------------------------------------------------- 1 | ../proc/wait1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig8.8: -------------------------------------------------------------------------------- 1 | ../proc/fork2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/fig9.12: -------------------------------------------------------------------------------- 1 | ../relation/orphan3.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figB.1: -------------------------------------------------------------------------------- 1 | ../include/apue.h -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figB.3: -------------------------------------------------------------------------------- 1 | ../lib/error.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figB.4: -------------------------------------------------------------------------------- 1 | ../lib/errorlog.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.1: -------------------------------------------------------------------------------- 1 | ../exercises/openmax.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.10: -------------------------------------------------------------------------------- 1 | ../exercises/zombie.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.12: -------------------------------------------------------------------------------- 1 | ../exercises/goodexit.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.13: -------------------------------------------------------------------------------- 1 | ../exercises/sleep.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.14: -------------------------------------------------------------------------------- 1 | ../exercises/getlogin.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.15: -------------------------------------------------------------------------------- 1 | ../exercises/pendlock.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.16: -------------------------------------------------------------------------------- 1 | ../exercises/sleepus_select.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.17: -------------------------------------------------------------------------------- 1 | ../exercises/sleepus_poll.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.18: -------------------------------------------------------------------------------- 1 | ../exercises/sizepipe.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.20: -------------------------------------------------------------------------------- 1 | ../exercises/fifo1.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.22: -------------------------------------------------------------------------------- 1 | ../exercises/bo.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.23: -------------------------------------------------------------------------------- 1 | ../exercises/asyncsocket.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.24: -------------------------------------------------------------------------------- 1 | ../exercises/pollmsg2.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.3: -------------------------------------------------------------------------------- 1 | ../exercises/longpath.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.4: -------------------------------------------------------------------------------- 1 | ../exercises/fmemopen.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.5: -------------------------------------------------------------------------------- 1 | ../exercises/getpwsvr4.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.6: -------------------------------------------------------------------------------- 1 | ../exercises/getpw44bsd.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.7: -------------------------------------------------------------------------------- 1 | ../exercises/prtime.c -------------------------------------------------------------------------------- /apue/apue.3e/figlinks/figC.8: -------------------------------------------------------------------------------- 1 | ../exercises/vfork3.c -------------------------------------------------------------------------------- /apue/apue.3e/filedir/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | ifeq "$(PLATFORM)" "linux" 6 | ZAP = zap 7 | else 8 | ZAP = 9 | endif 10 | 11 | 12 | PROGS = access cdpwd changemod devrdev filetype mycd umask unlink $(ZAP) 13 | MOREPROGS = ftw8 14 | 15 | all: $(PROGS) $(MOREPROGS) 16 | 17 | %: %.c $(LIBAPUE) 18 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 19 | 20 | ftw8: ftw8.c $(LIBAPUE) 21 | $(CC) $(CFLAGS) $(NAMEMAX) ftw8.c -o ftw8 $(LDFLAGS) $(LDLIBS) 22 | 23 | clean: 24 | rm -f $(PROGS) $(MOREPROGS) $(TEMPFILES) *.o $(ZAP) 25 | 26 | include $(ROOT)/Make.libapue.inc 27 | -------------------------------------------------------------------------------- /apue/apue.3e/filedir/access: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/filedir/access -------------------------------------------------------------------------------- /apue/apue.3e/filedir/access.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(int argc, char *argv[]) 6 | { 7 | if (argc != 2) 8 | err_quit("usage: a.out "); 9 | if (access(argv[1], R_OK) < 0) 10 | err_ret("access error for %s", argv[1]); 11 | else 12 | printf("read access OK\n"); 13 | if (open(argv[1], O_RDONLY) < 0) 14 | err_ret("open error for %s", argv[1]); 15 | else 16 | printf("open for reading OK\n"); 17 | exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /apue/apue.3e/filedir/cdpwd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/filedir/cdpwd -------------------------------------------------------------------------------- /apue/apue.3e/filedir/cdpwd.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | char *ptr; 7 | size_t size; 8 | 9 | if (chdir("/usr/spool/uucppublic") < 0) 10 | err_sys("chdir failed"); 11 | 12 | ptr = path_alloc(&size); /* our own function */ 13 | if (getcwd(ptr, size) == NULL) 14 | err_sys("getcwd failed"); 15 | 16 | printf("cwd = %s\n", ptr); 17 | exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /apue/apue.3e/filedir/changemod: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/filedir/changemod -------------------------------------------------------------------------------- /apue/apue.3e/filedir/changemod.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | struct stat statbuf; 7 | 8 | /* turn on set-group-ID and turn off group-execute */ 9 | 10 | if (stat("foo", &statbuf) < 0) 11 | err_sys("stat error for foo"); 12 | if (chmod("foo", (statbuf.st_mode & ~S_IXGRP) | S_ISGID) < 0) 13 | err_sys("chmod error for foo"); 14 | 15 | /* set absolute mode to "rw-r--r--" */ 16 | 17 | if (chmod("bar", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0) 18 | err_sys("chmod error for bar"); 19 | 20 | exit(0); 21 | } 22 | -------------------------------------------------------------------------------- /apue/apue.3e/filedir/devrdev: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/filedir/devrdev -------------------------------------------------------------------------------- /apue/apue.3e/filedir/filetype: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/filedir/filetype -------------------------------------------------------------------------------- /apue/apue.3e/filedir/ftw8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/filedir/ftw8 -------------------------------------------------------------------------------- /apue/apue.3e/filedir/mycd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/filedir/mycd -------------------------------------------------------------------------------- /apue/apue.3e/filedir/mycd.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | if (chdir("/tmp") < 0) 7 | err_sys("chdir failed"); 8 | printf("chdir to /tmp succeeded\n"); 9 | exit(0); 10 | } 11 | -------------------------------------------------------------------------------- /apue/apue.3e/filedir/umask: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/filedir/umask -------------------------------------------------------------------------------- /apue/apue.3e/filedir/umask.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define RWRWRW (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) 5 | 6 | int 7 | main(void) 8 | { 9 | umask(0); 10 | if (creat("foo", RWRWRW) < 0) 11 | err_sys("creat error for foo"); 12 | umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); 13 | if (creat("bar", RWRWRW) < 0) 14 | err_sys("creat error for bar"); 15 | exit(0); 16 | } 17 | -------------------------------------------------------------------------------- /apue/apue.3e/filedir/unlink: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/filedir/unlink -------------------------------------------------------------------------------- /apue/apue.3e/filedir/unlink.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | if (open("tempfile", O_RDWR) < 0) 8 | err_sys("open error"); 9 | if (unlink("tempfile") < 0) 10 | err_sys("unlink error"); 11 | printf("file unlinked\n"); 12 | sleep(15); 13 | printf("done\n"); 14 | exit(0); 15 | } 16 | -------------------------------------------------------------------------------- /apue/apue.3e/filedir/zap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/filedir/zap -------------------------------------------------------------------------------- /apue/apue.3e/fileio/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | PROGS = fileflags hole mycat seek 6 | 7 | all: $(PROGS) setfl.o 8 | 9 | %: %.c $(LIBAPUE) 10 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 11 | 12 | clean: 13 | rm -f $(PROGS) $(TEMPFILES) *.o file.hole 14 | 15 | include $(ROOT)/Make.libapue.inc 16 | -------------------------------------------------------------------------------- /apue/apue.3e/fileio/fileflags: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/fileio/fileflags -------------------------------------------------------------------------------- /apue/apue.3e/fileio/hole: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/fileio/hole -------------------------------------------------------------------------------- /apue/apue.3e/fileio/hole.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | char buf1[] = "abcdefghij"; 5 | char buf2[] = "ABCDEFGHIJ"; 6 | 7 | int 8 | main(void) 9 | { 10 | int fd; 11 | 12 | if ((fd = creat("file.hole", FILE_MODE)) < 0) 13 | err_sys("creat error"); 14 | 15 | if (write(fd, buf1, 10) != 10) 16 | err_sys("buf1 write error"); 17 | /* offset now = 10 */ 18 | 19 | if (lseek(fd, 16384, SEEK_SET) == -1) 20 | err_sys("lseek error"); 21 | /* offset now = 16384 */ 22 | 23 | if (write(fd, buf2, 10) != 10) 24 | err_sys("buf2 write error"); 25 | /* offset now = 16394 */ 26 | 27 | exit(0); 28 | } 29 | -------------------------------------------------------------------------------- /apue/apue.3e/fileio/mycat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/fileio/mycat -------------------------------------------------------------------------------- /apue/apue.3e/fileio/mycat.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | #define BUFFSIZE 4096 4 | 5 | int 6 | main(void) 7 | { 8 | int n; 9 | char buf[BUFFSIZE]; 10 | 11 | while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0) 12 | if (write(STDOUT_FILENO, buf, n) != n) 13 | err_sys("write error"); 14 | 15 | if (n < 0) 16 | err_sys("read error"); 17 | 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /apue/apue.3e/fileio/seek: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/fileio/seek -------------------------------------------------------------------------------- /apue/apue.3e/fileio/seek.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | if (lseek(STDIN_FILENO, 0, SEEK_CUR) == -1) 7 | printf("cannot seek\n"); 8 | else 9 | printf("seek OK\n"); 10 | exit(0); 11 | } 12 | -------------------------------------------------------------------------------- /apue/apue.3e/fileio/setfl.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | void 5 | set_fl(int fd, int flags) /* flags are file status flags to turn on */ 6 | { 7 | int val; 8 | 9 | if ((val = fcntl(fd, F_GETFL, 0)) < 0) 10 | err_sys("fcntl F_GETFL error"); 11 | 12 | val |= flags; /* turn on flags */ 13 | 14 | if (fcntl(fd, F_SETFL, val) < 0) 15 | err_sys("fcntl F_SETFL error"); 16 | } 17 | -------------------------------------------------------------------------------- /apue/apue.3e/intro/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | PROGS = getcputc hello ls1 mycat shell1 shell2 testerror uidgid 6 | 7 | all: $(PROGS) 8 | 9 | %: %.c $(LIBAPUE) 10 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 11 | 12 | clean: 13 | rm -f $(PROGS) $(TEMPFILES) *.o 14 | 15 | include $(ROOT)/Make.libapue.inc 16 | -------------------------------------------------------------------------------- /apue/apue.3e/intro/getcputc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/intro/getcputc -------------------------------------------------------------------------------- /apue/apue.3e/intro/getcputc.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | int c; 7 | 8 | while ((c = getc(stdin)) != EOF) 9 | if (putc(c, stdout) == EOF) 10 | err_sys("output error"); 11 | 12 | if (ferror(stdin)) 13 | err_sys("input error"); 14 | 15 | exit(0); 16 | } 17 | -------------------------------------------------------------------------------- /apue/apue.3e/intro/hello: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/intro/hello -------------------------------------------------------------------------------- /apue/apue.3e/intro/hello.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | printf("hello world from process ID %ld\n", (long)getpid()); 7 | exit(0); 8 | } 9 | -------------------------------------------------------------------------------- /apue/apue.3e/intro/ls1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/intro/ls1 -------------------------------------------------------------------------------- /apue/apue.3e/intro/ls1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(int argc, char *argv[]) 6 | { 7 | DIR *dp; 8 | struct dirent *dirp; 9 | 10 | if (argc != 2) 11 | err_quit("usage: ls directory_name"); 12 | 13 | if ((dp = opendir(argv[1])) == NULL) 14 | err_sys("can't open %s", argv[1]); 15 | while ((dirp = readdir(dp)) != NULL) 16 | printf("%s\n", dirp->d_name); 17 | 18 | closedir(dp); 19 | exit(0); 20 | } 21 | -------------------------------------------------------------------------------- /apue/apue.3e/intro/mycat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/intro/mycat -------------------------------------------------------------------------------- /apue/apue.3e/intro/mycat.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | #define BUFFSIZE 4096 4 | 5 | int 6 | main(void) 7 | { 8 | int n; 9 | char buf[BUFFSIZE]; 10 | 11 | while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0) 12 | if (write(STDOUT_FILENO, buf, n) != n) 13 | err_sys("write error"); 14 | 15 | if (n < 0) 16 | err_sys("read error"); 17 | 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /apue/apue.3e/intro/shell1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/intro/shell1 -------------------------------------------------------------------------------- /apue/apue.3e/intro/shell2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/intro/shell2 -------------------------------------------------------------------------------- /apue/apue.3e/intro/testerror: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/intro/testerror -------------------------------------------------------------------------------- /apue/apue.3e/intro/testerror.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(int argc, char *argv[]) 6 | { 7 | fprintf(stderr, "EACCES: %s\n", strerror(EACCES)); 8 | errno = ENOENT; 9 | perror(argv[0]); 10 | exit(0); 11 | } 12 | -------------------------------------------------------------------------------- /apue/apue.3e/intro/uidgid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/intro/uidgid -------------------------------------------------------------------------------- /apue/apue.3e/intro/uidgid.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | printf("uid = %d, gid = %d\n", getuid(), getgid()); 7 | exit(0); 8 | } 9 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | PROGS = add2 add2stdio devzero myuclc pipe1 pipe2 pipe4 popen1 popen2 tshm 6 | 7 | all: $(PROGS) popen.o slock.o tellwait.o 8 | 9 | %: %.c $(LIBAPUE) 10 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 11 | 12 | slock.o: slock.c slock.h 13 | 14 | clean: 15 | rm -f $(PROGS) $(TEMPFILES) *.o 16 | 17 | include $(ROOT)/Make.libapue.inc 18 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/add2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc1/add2 -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/add2.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | int n, int1, int2; 7 | char line[MAXLINE]; 8 | 9 | while ((n = read(STDIN_FILENO, line, MAXLINE)) > 0) { 10 | line[n] = 0; /* null terminate */ 11 | if (sscanf(line, "%d%d", &int1, &int2) == 2) { 12 | sprintf(line, "%d\n", int1 + int2); 13 | n = strlen(line); 14 | if (write(STDOUT_FILENO, line, n) != n) 15 | err_sys("write error"); 16 | } else { 17 | if (write(STDOUT_FILENO, "invalid args\n", 13) != 13) 18 | err_sys("write error"); 19 | } 20 | } 21 | exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/add2stdio: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc1/add2stdio -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/add2stdio.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | int int1, int2; 7 | char line[MAXLINE]; 8 | 9 | while (fgets(line, MAXLINE, stdin) != NULL) { 10 | if (sscanf(line, "%d%d", &int1, &int2) == 2) { 11 | if (printf("%d\n", int1 + int2) == EOF) 12 | err_sys("printf error"); 13 | } else { 14 | if (printf("invalid args\n") == EOF) 15 | err_sys("printf error"); 16 | } 17 | } 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/devzero: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc1/devzero -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/myuclc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc1/myuclc -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/myuclc.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | int c; 8 | 9 | while ((c = getchar()) != EOF) { 10 | if (isupper(c)) 11 | c = tolower(c); 12 | if (putchar(c) == EOF) 13 | err_sys("output error"); 14 | if (c == '\n') 15 | fflush(stdout); 16 | } 17 | exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/pipe1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc1/pipe1 -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/pipe1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | int n; 7 | int fd[2]; 8 | pid_t pid; 9 | char line[MAXLINE]; 10 | 11 | if (pipe(fd) < 0) 12 | err_sys("pipe error"); 13 | if ((pid = fork()) < 0) { 14 | err_sys("fork error"); 15 | } else if (pid > 0) { /* parent */ 16 | close(fd[0]); 17 | write(fd[1], "hello world\n", 12); 18 | } else { /* child */ 19 | close(fd[1]); 20 | n = read(fd[0], line, MAXLINE); 21 | write(STDOUT_FILENO, line, n); 22 | } 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/pipe2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc1/pipe2 -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/pipe4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc1/pipe4 -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/popen1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc1/popen1 -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/popen1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | char line[MAXLINE]; 8 | FILE *fpin; 9 | 10 | if ((fpin = popen("myuclc", "r")) == NULL) 11 | err_sys("popen error"); 12 | for ( ; ; ) { 13 | fputs("prompt> ", stdout); 14 | fflush(stdout); 15 | if (fgets(line, MAXLINE, fpin) == NULL) /* read from pipe */ 16 | break; 17 | if (fputs(line, stdout) == EOF) 18 | err_sys("fputs error to pipe"); 19 | } 20 | if (pclose(fpin) == -1) 21 | err_sys("pclose error"); 22 | putchar('\n'); 23 | exit(0); 24 | } 25 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/popen2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc1/popen2 -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/slock.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | struct slock { 7 | sem_t *semp; 8 | char name[_POSIX_NAME_MAX]; 9 | }; 10 | 11 | struct slock * s_alloc(); 12 | void s_free(struct slock *); 13 | int s_lock(struct slock *); 14 | int s_trylock(struct slock *); 15 | int s_unlock(struct slock *); 16 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc1/tshm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc1/tshm -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/bindunix: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc2/bindunix -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/bindunix.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | #include 4 | 5 | int 6 | main(void) 7 | { 8 | int fd, size; 9 | struct sockaddr_un un; 10 | 11 | un.sun_family = AF_UNIX; 12 | strcpy(un.sun_path, "foo.socket"); 13 | if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) 14 | err_sys("socket failed"); 15 | size = offsetof(struct sockaddr_un, sun_path) + strlen(un.sun_path); 16 | if (bind(fd, (struct sockaddr *)&un, size) < 0) 17 | err_sys("bind failed"); 18 | printf("UNIX domain socket bound\n"); 19 | exit(0); 20 | } 21 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/open.fe/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=../.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | ifeq "$(PLATFORM)" "solaris" 6 | EXTRALIBS=-lsocket -lnsl 7 | endif 8 | 9 | PROGS = openclient 10 | 11 | all: $(PROGS) 12 | 13 | openclient: main.o open.o $(LIBAPUE) 14 | $(CC) $(CFLAGS) -o openclient main.o open.o $(LDFLAGS) $(LDLIBS) 15 | 16 | clean: 17 | rm -f $(PROGS) $(TEMPFILES) *.o 18 | 19 | include $(ROOT)/Make.libapue.inc 20 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/open.fe/open.h: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define CL_OPEN "open" /* client's request for server */ 5 | 6 | int csopen(char *, int); 7 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/open.fe/openclient: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc2/open.fe/openclient -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/open/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=../.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | ifeq "$(PLATFORM)" "solaris" 6 | EXTRALIBS=-lsocket -lnsl 7 | endif 8 | 9 | PROGS = openclient 10 | 11 | all: $(PROGS) 12 | 13 | openclient: main.o open.o $(LIBAPUE) 14 | $(CC) $(CFLAGS) -o openclient main.o open.o $(LDFLAGS) $(LDLIBS) 15 | 16 | clean: 17 | rm -f $(PROGS) $(TEMPFILES) *.o 18 | 19 | include $(ROOT)/Make.libapue.inc 20 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/open/open.h: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define CL_OPEN "open" /* client's request for server */ 5 | #define CS_OPEN "/tmp/opend.socket" /* server's well-known name */ 6 | 7 | int csopen(char *, int); 8 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/open/openclient: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc2/open/openclient -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/opend.fe/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=../.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | ifeq "$(PLATFORM)" "solaris" 6 | EXTRALIBS=-lsocket -lnsl 7 | endif 8 | 9 | PROGS = opend 10 | 11 | all: $(PROGS) 12 | 13 | opend: main.o request.o cliargs.o $(LIBAPUE) 14 | $(CC) $(CFLAGS) -o opend main.o cliargs.o request.o $(LDFLAGS) $(LDLIBS) 15 | 16 | clean: 17 | rm -f $(PROGS) $(TEMPFILES) *.o 18 | 19 | include $(ROOT)/Make.libapue.inc 20 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/opend.fe/cliargs.c: -------------------------------------------------------------------------------- 1 | #include "opend.h" 2 | 3 | /* 4 | * This function is called by buf_args(), which is called by 5 | * handle_request(). buf_args() has broken up the client's 6 | * buffer into an argv[]-style array, which we now process. 7 | */ 8 | int 9 | cli_args(int argc, char **argv) 10 | { 11 | if (argc != 3 || strcmp(argv[0], CL_OPEN) != 0) { 12 | strcpy(errmsg, "usage: \n"); 13 | return(-1); 14 | } 15 | pathname = argv[1]; /* save ptr to pathname to open */ 16 | oflag = atoi(argv[2]); 17 | return(0); 18 | } 19 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/opend.fe/main.c: -------------------------------------------------------------------------------- 1 | #include "opend.h" 2 | 3 | char errmsg[MAXLINE]; 4 | int oflag; 5 | char *pathname; 6 | 7 | int 8 | main(void) 9 | { 10 | int nread; 11 | char buf[MAXLINE]; 12 | 13 | for ( ; ; ) { /* read arg buffer from client, process request */ 14 | if ((nread = read(STDIN_FILENO, buf, MAXLINE)) < 0) 15 | err_sys("read error on stream pipe"); 16 | else if (nread == 0) 17 | break; /* client has closed the stream pipe */ 18 | handle_request(buf, nread, STDOUT_FILENO); 19 | } 20 | exit(0); 21 | } 22 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/opend.fe/opend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc2/opend.fe/opend -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/opend.fe/opend.h: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define CL_OPEN "open" /* client's request for server */ 5 | 6 | extern char errmsg[]; /* error message string to return to client */ 7 | extern int oflag; /* open() flag: O_xxx ... */ 8 | extern char *pathname; /* of file to open() for client */ 9 | 10 | int cli_args(int, char **); 11 | void handle_request(char *, int, int); 12 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/opend/cliargs.c: -------------------------------------------------------------------------------- 1 | #include "opend.h" 2 | 3 | /* 4 | * This function is called by buf_args(), which is called by 5 | * handle_request(). buf_args() has broken up the client's 6 | * buffer into an argv[] style array, which we now process. 7 | */ 8 | int 9 | cli_args(int argc, char **argv) 10 | { 11 | if (argc != 3 || strcmp(argv[0], CL_OPEN) != 0) { 12 | strcpy(errmsg, "usage: \n"); 13 | return(-1); 14 | } 15 | pathname = argv[1]; /* save ptr to pathname to open */ 16 | oflag = atoi(argv[2]); 17 | return(0); 18 | } 19 | -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/opend/opend.poll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc2/opend/opend.poll -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/opend/opend.select: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc2/opend/opend.select -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/pollmsg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc2/pollmsg -------------------------------------------------------------------------------- /apue/apue.3e/ipc2/sendmsg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/ipc2/sendmsg -------------------------------------------------------------------------------- /apue/apue.3e/lib/clrfl.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | void 5 | clr_fl(int fd, int flags) 6 | /* flags are the file status flags to turn off */ 7 | { 8 | int val; 9 | 10 | if ((val = fcntl(fd, F_GETFL, 0)) < 0) 11 | err_sys("fcntl F_GETFL error"); 12 | 13 | val &= ~flags; /* turn flags off */ 14 | 15 | if (fcntl(fd, F_SETFL, val) < 0) 16 | err_sys("fcntl F_SETFL error"); 17 | } 18 | -------------------------------------------------------------------------------- /apue/apue.3e/lib/lockreg.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | lock_reg(int fd, int cmd, int type, off_t offset, int whence, off_t len) 6 | { 7 | struct flock lock; 8 | 9 | lock.l_type = type; /* F_RDLCK, F_WRLCK, F_UNLCK */ 10 | lock.l_start = offset; /* byte offset, relative to l_whence */ 11 | lock.l_whence = whence; /* SEEK_SET, SEEK_CUR, SEEK_END */ 12 | lock.l_len = len; /* #bytes (0 means to EOF) */ 13 | 14 | return(fcntl(fd, cmd, &lock)); 15 | } 16 | -------------------------------------------------------------------------------- /apue/apue.3e/lib/locktest.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | pid_t 5 | lock_test(int fd, int type, off_t offset, int whence, off_t len) 6 | { 7 | struct flock lock; 8 | 9 | lock.l_type = type; /* F_RDLCK or F_WRLCK */ 10 | lock.l_start = offset; /* byte offset, relative to l_whence */ 11 | lock.l_whence = whence; /* SEEK_SET, SEEK_CUR, SEEK_END */ 12 | lock.l_len = len; /* #bytes (0 means to EOF) */ 13 | 14 | if (fcntl(fd, F_GETLK, &lock) < 0) 15 | err_sys("fcntl error"); 16 | 17 | if (lock.l_type == F_UNLCK) 18 | return(0); /* false, region isn't locked by another proc */ 19 | return(lock.l_pid); /* true, return pid of lock owner */ 20 | } 21 | -------------------------------------------------------------------------------- /apue/apue.3e/lib/openmax.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | #include 4 | 5 | #ifdef OPEN_MAX 6 | static long openmax = OPEN_MAX; 7 | #else 8 | static long openmax = 0; 9 | #endif 10 | 11 | /* 12 | * If OPEN_MAX is indeterminate, this might be inadequate. 13 | */ 14 | #define OPEN_MAX_GUESS 256 15 | 16 | long 17 | open_max(void) 18 | { 19 | if (openmax == 0) { /* first time through */ 20 | errno = 0; 21 | if ((openmax = sysconf(_SC_OPEN_MAX)) < 0) { 22 | if (errno == 0) 23 | openmax = OPEN_MAX_GUESS; /* it's indeterminate */ 24 | else 25 | err_sys("sysconf error for _SC_OPEN_MAX"); 26 | } 27 | } 28 | return(openmax); 29 | } 30 | -------------------------------------------------------------------------------- /apue/apue.3e/lib/prexit.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | void 5 | pr_exit(int status) 6 | { 7 | if (WIFEXITED(status)) 8 | printf("normal termination, exit status = %d\n", 9 | WEXITSTATUS(status)); 10 | else if (WIFSIGNALED(status)) 11 | printf("abnormal termination, signal number = %d%s\n", 12 | WTERMSIG(status), 13 | #ifdef WCOREDUMP 14 | WCOREDUMP(status) ? " (core file generated)" : ""); 15 | #else 16 | ""); 17 | #endif 18 | else if (WIFSTOPPED(status)) 19 | printf("child stopped, signal number = %d\n", 20 | WSTOPSIG(status)); 21 | } 22 | -------------------------------------------------------------------------------- /apue/apue.3e/lib/readn.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | ssize_t /* Read "n" bytes from a descriptor */ 4 | readn(int fd, void *ptr, size_t n) 5 | { 6 | size_t nleft; 7 | ssize_t nread; 8 | 9 | nleft = n; 10 | while (nleft > 0) { 11 | if ((nread = read(fd, ptr, nleft)) < 0) { 12 | if (nleft == n) 13 | return(-1); /* error, return -1 */ 14 | else 15 | break; /* error, return amount read so far */ 16 | } else if (nread == 0) { 17 | break; /* EOF */ 18 | } 19 | nleft -= nread; 20 | ptr += nread; 21 | } 22 | return(n - nleft); /* return >= 0 */ 23 | } 24 | -------------------------------------------------------------------------------- /apue/apue.3e/lib/senderr.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | /* 4 | * Used when we had planned to send an fd using send_fd(), 5 | * but encountered an error instead. We send the error back 6 | * using the send_fd()/recv_fd() protocol. 7 | */ 8 | int 9 | send_err(int fd, int errcode, const char *msg) 10 | { 11 | int n; 12 | 13 | if ((n = strlen(msg)) > 0) 14 | if (writen(fd, msg, n) != n) /* send the error message */ 15 | return(-1); 16 | 17 | if (errcode >= 0) 18 | errcode = -1; /* must be negative */ 19 | 20 | if (send_fd(fd, errcode) < 0) 21 | return(-1); 22 | 23 | return(0); 24 | } 25 | -------------------------------------------------------------------------------- /apue/apue.3e/lib/setfd.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | set_cloexec(int fd) 6 | { 7 | int val; 8 | 9 | if ((val = fcntl(fd, F_GETFD, 0)) < 0) 10 | return(-1); 11 | 12 | val |= FD_CLOEXEC; /* enable close-on-exec */ 13 | 14 | return(fcntl(fd, F_SETFD, val)); 15 | } 16 | -------------------------------------------------------------------------------- /apue/apue.3e/lib/setfl.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | void 5 | set_fl(int fd, int flags) /* flags are file status flags to turn on */ 6 | { 7 | int val; 8 | 9 | if ((val = fcntl(fd, F_GETFL, 0)) < 0) 10 | err_sys("fcntl F_GETFL error"); 11 | 12 | val |= flags; /* turn on flags */ 13 | 14 | if (fcntl(fd, F_SETFL, val) < 0) 15 | err_sys("fcntl F_SETFL error"); 16 | } 17 | -------------------------------------------------------------------------------- /apue/apue.3e/lib/signal.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | /* Reliable version of signal(), using POSIX sigaction(). */ 4 | Sigfunc * 5 | signal(int signo, Sigfunc *func) 6 | { 7 | struct sigaction act, oact; 8 | 9 | act.sa_handler = func; 10 | sigemptyset(&act.sa_mask); 11 | act.sa_flags = 0; 12 | if (signo == SIGALRM) { 13 | #ifdef SA_INTERRUPT 14 | act.sa_flags |= SA_INTERRUPT; 15 | #endif 16 | } else { 17 | act.sa_flags |= SA_RESTART; 18 | } 19 | if (sigaction(signo, &act, &oact) < 0) 20 | return(SIG_ERR); 21 | return(oact.sa_handler); 22 | } 23 | -------------------------------------------------------------------------------- /apue/apue.3e/lib/signalintr.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | Sigfunc * 4 | signal_intr(int signo, Sigfunc *func) 5 | { 6 | struct sigaction act, oact; 7 | 8 | act.sa_handler = func; 9 | sigemptyset(&act.sa_mask); 10 | act.sa_flags = 0; 11 | #ifdef SA_INTERRUPT 12 | act.sa_flags |= SA_INTERRUPT; 13 | #endif 14 | if (sigaction(signo, &act, &oact) < 0) 15 | return(SIG_ERR); 16 | return(oact.sa_handler); 17 | } 18 | -------------------------------------------------------------------------------- /apue/apue.3e/lib/sleepus.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | void 5 | sleep_us(unsigned int nusecs) 6 | { 7 | struct timeval tval; 8 | 9 | tval.tv_sec = nusecs / 1000000; 10 | tval.tv_usec = nusecs % 1000000; 11 | select(0, NULL, NULL, NULL, &tval); 12 | } 13 | -------------------------------------------------------------------------------- /apue/apue.3e/lib/spipe.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | /* 5 | * Returns a full-duplex pipe (a UNIX domain socket) with 6 | * the two file descriptors returned in fd[0] and fd[1]. 7 | */ 8 | int 9 | fd_pipe(int fd[2]) 10 | { 11 | return(socketpair(AF_UNIX, SOCK_STREAM, 0, fd)); 12 | } 13 | -------------------------------------------------------------------------------- /apue/apue.3e/lib/strerror.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef LINUX 4 | extern char *sys_errlist[]; 5 | extern int sys_nerr; 6 | #endif 7 | 8 | char * 9 | strerror(int error) 10 | { 11 | static char mesg[30]; 12 | 13 | if (error >= 0 && error <= sys_nerr) 14 | return((char *)sys_errlist[error]); 15 | 16 | sprintf(mesg, "Unknown error (%d)", error); 17 | return(mesg); 18 | } 19 | -------------------------------------------------------------------------------- /apue/apue.3e/lib/writen.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | ssize_t /* Write "n" bytes to a descriptor */ 4 | writen(int fd, const void *ptr, size_t n) 5 | { 6 | size_t nleft; 7 | ssize_t nwritten; 8 | 9 | nleft = n; 10 | while (nleft > 0) { 11 | if ((nwritten = write(fd, ptr, nleft)) < 0) { 12 | if (nleft == n) 13 | return(-1); /* error, return -1 */ 14 | else 15 | break; /* error, return amount written so far */ 16 | } else if (nwritten == 0) { 17 | break; 18 | } 19 | nleft -= nwritten; 20 | ptr += nwritten; 21 | } 22 | return(n - nleft); /* return >= 0 */ 23 | } 24 | -------------------------------------------------------------------------------- /apue/apue.3e/printer/print: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/printer/print -------------------------------------------------------------------------------- /apue/apue.3e/printer/printd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/printer/printd -------------------------------------------------------------------------------- /apue/apue.3e/proc/awkexample: -------------------------------------------------------------------------------- 1 | #!/usr/bin/awk -f 2 | # Note: on Solaris, use nawk instead 3 | BEGIN { 4 | for (i = 0; i < ARGC; i++) 5 | printf "ARGV[%d] = %s\n", i, ARGV[i] 6 | exit 7 | } 8 | -------------------------------------------------------------------------------- /apue/apue.3e/proc/echoall: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/proc/echoall -------------------------------------------------------------------------------- /apue/apue.3e/proc/echoall.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(int argc, char *argv[]) 5 | { 6 | int i; 7 | char **ptr; 8 | extern char **environ; 9 | 10 | for (i = 0; i < argc; i++) /* echo all command-line args */ 11 | printf("argv[%d]: %s\n", i, argv[i]); 12 | 13 | for (ptr = environ; *ptr != 0; ptr++) /* and all env strings */ 14 | printf("%s\n", *ptr); 15 | 16 | exit(0); 17 | } 18 | -------------------------------------------------------------------------------- /apue/apue.3e/proc/exec1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/proc/exec1 -------------------------------------------------------------------------------- /apue/apue.3e/proc/exec2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/proc/exec2 -------------------------------------------------------------------------------- /apue/apue.3e/proc/exec2.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | pid_t pid; 8 | 9 | if ((pid = fork()) < 0) { 10 | err_sys("fork error"); 11 | } else if (pid == 0) { /* child */ 12 | if (execl("/home/sar/bin/testinterp", 13 | "testinterp", "myarg1", "MY ARG2", (char *)0) < 0) 14 | err_sys("execl error"); 15 | } 16 | if (waitpid(pid, NULL, 0) < 0) /* parent */ 17 | err_sys("waitpid error"); 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /apue/apue.3e/proc/fork1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/proc/fork1 -------------------------------------------------------------------------------- /apue/apue.3e/proc/fork2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/proc/fork2 -------------------------------------------------------------------------------- /apue/apue.3e/proc/nice: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/proc/nice -------------------------------------------------------------------------------- /apue/apue.3e/proc/pracct: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/proc/pracct -------------------------------------------------------------------------------- /apue/apue.3e/proc/pruids: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/proc/pruids -------------------------------------------------------------------------------- /apue/apue.3e/proc/pruids.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | printf("real uid = %d, effective uid = %d\n", getuid(), geteuid()); 7 | exit(0); 8 | } 9 | -------------------------------------------------------------------------------- /apue/apue.3e/proc/systest1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/proc/systest1 -------------------------------------------------------------------------------- /apue/apue.3e/proc/systest1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | int status; 8 | 9 | if ((status = system("date")) < 0) 10 | err_sys("system() error"); 11 | 12 | pr_exit(status); 13 | 14 | if ((status = system("nosuchcommand")) < 0) 15 | err_sys("system() error"); 16 | 17 | pr_exit(status); 18 | 19 | if ((status = system("who; exit 44")) < 0) 20 | err_sys("system() error"); 21 | 22 | pr_exit(status); 23 | 24 | exit(0); 25 | } 26 | -------------------------------------------------------------------------------- /apue/apue.3e/proc/systest3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/proc/systest3 -------------------------------------------------------------------------------- /apue/apue.3e/proc/systest3.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(int argc, char *argv[]) 5 | { 6 | int status; 7 | 8 | if (argc < 2) 9 | err_quit("command-line argument required"); 10 | 11 | if ((status = system(argv[1])) < 0) 12 | err_sys("system() error"); 13 | 14 | pr_exit(status); 15 | 16 | exit(0); 17 | } 18 | -------------------------------------------------------------------------------- /apue/apue.3e/proc/tellwait1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/proc/tellwait1 -------------------------------------------------------------------------------- /apue/apue.3e/proc/tellwait1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | static void charatatime(char *); 4 | 5 | int 6 | main(void) 7 | { 8 | pid_t pid; 9 | 10 | if ((pid = fork()) < 0) { 11 | err_sys("fork error"); 12 | } else if (pid == 0) { 13 | charatatime("output from child\n"); 14 | } else { 15 | charatatime("output from parent\n"); 16 | } 17 | exit(0); 18 | } 19 | 20 | static void 21 | charatatime(char *str) 22 | { 23 | char *ptr; 24 | int c; 25 | 26 | setbuf(stdout, NULL); /* set unbuffered */ 27 | for (ptr = str; (c = *ptr++) != 0; ) 28 | putc(c, stdout); 29 | } 30 | -------------------------------------------------------------------------------- /apue/apue.3e/proc/tellwait2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/proc/tellwait2 -------------------------------------------------------------------------------- /apue/apue.3e/proc/tellwait2.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | static void charatatime(char *); 4 | 5 | int 6 | main(void) 7 | { 8 | pid_t pid; 9 | 10 | TELL_WAIT(); 11 | 12 | if ((pid = fork()) < 0) { 13 | err_sys("fork error"); 14 | } else if (pid == 0) { 15 | WAIT_PARENT(); /* parent goes first */ 16 | charatatime("output from child\n"); 17 | } else { 18 | charatatime("output from parent\n"); 19 | TELL_CHILD(pid); 20 | } 21 | exit(0); 22 | } 23 | 24 | static void 25 | charatatime(char *str) 26 | { 27 | char *ptr; 28 | int c; 29 | 30 | setbuf(stdout, NULL); /* set unbuffered */ 31 | for (ptr = str; (c = *ptr++) != 0; ) 32 | putc(c, stdout); 33 | } 34 | -------------------------------------------------------------------------------- /apue/apue.3e/proc/test1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/proc/test1 -------------------------------------------------------------------------------- /apue/apue.3e/proc/times1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/proc/times1 -------------------------------------------------------------------------------- /apue/apue.3e/proc/vfork1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/proc/vfork1 -------------------------------------------------------------------------------- /apue/apue.3e/proc/vfork1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int globvar = 6; /* external variable in initialized data */ 4 | 5 | int 6 | main(void) 7 | { 8 | int var; /* automatic variable on the stack */ 9 | pid_t pid; 10 | 11 | var = 88; 12 | printf("before vfork\n"); /* we don't flush stdio */ 13 | if ((pid = vfork()) < 0) { 14 | err_sys("vfork error"); 15 | } else if (pid == 0) { /* child */ 16 | globvar++; /* modify parent's variables */ 17 | var++; 18 | _exit(0); /* child terminates */ 19 | } 20 | 21 | /* parent continues here */ 22 | printf("pid = %ld, glob = %d, var = %d\n", (long)getpid(), globvar, 23 | var); 24 | exit(0); 25 | } 26 | -------------------------------------------------------------------------------- /apue/apue.3e/proc/wait1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/proc/wait1 -------------------------------------------------------------------------------- /apue/apue.3e/pty/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | ifeq "$(PLATFORM)" "solaris" 6 | EXTRALIBS=-lsocket -lnsl 7 | endif 8 | 9 | PROGS = pty 10 | 11 | all: $(PROGS) 12 | 13 | pty: main.o loop.o driver.o $(LIBAPUE) 14 | $(CC) $(CFLAGS) -o pty main.o loop.o driver.o $(LDFLAGS) $(LDLIBS) 15 | 16 | clean: 17 | rm -f $(PROGS) $(TEMPFILES) *.o 18 | 19 | include $(ROOT)/Make.libapue.inc 20 | -------------------------------------------------------------------------------- /apue/apue.3e/pty/pty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/pty/pty -------------------------------------------------------------------------------- /apue/apue.3e/relation/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | PROGS = orphan3 6 | 7 | all: $(PROGS) 8 | 9 | %: %.c $(LIBAPUE) 10 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 11 | 12 | clean: 13 | rm -f $(PROGS) $(TEMPFILES) *.o 14 | 15 | include $(ROOT)/Make.libapue.inc 16 | -------------------------------------------------------------------------------- /apue/apue.3e/relation/orphan3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/relation/orphan3 -------------------------------------------------------------------------------- /apue/apue.3e/signals/child: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/signals/child -------------------------------------------------------------------------------- /apue/apue.3e/signals/critical: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/signals/critical -------------------------------------------------------------------------------- /apue/apue.3e/signals/mask: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/signals/mask -------------------------------------------------------------------------------- /apue/apue.3e/signals/read1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/signals/read1 -------------------------------------------------------------------------------- /apue/apue.3e/signals/read1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | static void sig_alrm(int); 4 | 5 | int 6 | main(void) 7 | { 8 | int n; 9 | char line[MAXLINE]; 10 | 11 | if (signal(SIGALRM, sig_alrm) == SIG_ERR) 12 | err_sys("signal(SIGALRM) error"); 13 | 14 | alarm(10); 15 | if ((n = read(STDIN_FILENO, line, MAXLINE)) < 0) 16 | err_sys("read error"); 17 | alarm(0); 18 | 19 | write(STDOUT_FILENO, line, n); 20 | exit(0); 21 | } 22 | 23 | static void 24 | sig_alrm(int signo) 25 | { 26 | /* nothing to do, just return to interrupt the read */ 27 | } 28 | -------------------------------------------------------------------------------- /apue/apue.3e/signals/read2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/signals/read2 -------------------------------------------------------------------------------- /apue/apue.3e/signals/read2.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | static void sig_alrm(int); 5 | static jmp_buf env_alrm; 6 | 7 | int 8 | main(void) 9 | { 10 | int n; 11 | char line[MAXLINE]; 12 | 13 | if (signal(SIGALRM, sig_alrm) == SIG_ERR) 14 | err_sys("signal(SIGALRM) error"); 15 | if (setjmp(env_alrm) != 0) 16 | err_quit("read timeout"); 17 | 18 | alarm(10); 19 | if ((n = read(STDIN_FILENO, line, MAXLINE)) < 0) 20 | err_sys("read error"); 21 | alarm(0); 22 | 23 | write(STDOUT_FILENO, line, n); 24 | exit(0); 25 | } 26 | 27 | static void 28 | sig_alrm(int signo) 29 | { 30 | longjmp(env_alrm, 1); 31 | } 32 | -------------------------------------------------------------------------------- /apue/apue.3e/signals/reenter: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/signals/reenter -------------------------------------------------------------------------------- /apue/apue.3e/signals/reenter.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | static void 5 | my_alarm(int signo) 6 | { 7 | struct passwd *rootptr; 8 | 9 | printf("in signal handler\n"); 10 | if ((rootptr = getpwnam("root")) == NULL) 11 | err_sys("getpwnam(root) error"); 12 | alarm(1); 13 | } 14 | 15 | int 16 | main(void) 17 | { 18 | struct passwd *ptr; 19 | 20 | signal(SIGALRM, my_alarm); 21 | alarm(1); 22 | for ( ; ; ) { 23 | if ((ptr = getpwnam("sar")) == NULL) 24 | err_sys("getpwnam error"); 25 | if (strcmp(ptr->pw_name, "sar") != 0) 26 | printf("return value corrupted!, pw_name = %s\n", 27 | ptr->pw_name); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /apue/apue.3e/signals/sigtstp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/signals/sigtstp -------------------------------------------------------------------------------- /apue/apue.3e/signals/sigusr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/signals/sigusr -------------------------------------------------------------------------------- /apue/apue.3e/signals/sigusr.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | static void sig_usr(int); /* one handler for both signals */ 4 | 5 | int 6 | main(void) 7 | { 8 | if (signal(SIGUSR1, sig_usr) == SIG_ERR) 9 | err_sys("can't catch SIGUSR1"); 10 | if (signal(SIGUSR2, sig_usr) == SIG_ERR) 11 | err_sys("can't catch SIGUSR2"); 12 | for ( ; ; ) 13 | pause(); 14 | } 15 | 16 | static void 17 | sig_usr(int signo) /* argument is signal number */ 18 | { 19 | if (signo == SIGUSR1) 20 | printf("received SIGUSR1\n"); 21 | else if (signo == SIGUSR2) 22 | printf("received SIGUSR2\n"); 23 | else 24 | err_dump("received signal %d\n", signo); 25 | } 26 | -------------------------------------------------------------------------------- /apue/apue.3e/signals/sleep1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void 5 | sig_alrm(int signo) 6 | { 7 | /* nothing to do, just return to wake up the pause */ 8 | } 9 | 10 | unsigned int 11 | sleep1(unsigned int seconds) 12 | { 13 | if (signal(SIGALRM, sig_alrm) == SIG_ERR) 14 | return(seconds); 15 | alarm(seconds); /* start the timer */ 16 | pause(); /* next caught signal wakes us up */ 17 | return(alarm(0)); /* turn off timer, return unslept time */ 18 | } 19 | -------------------------------------------------------------------------------- /apue/apue.3e/signals/sleep2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static jmp_buf env_alrm; 6 | 7 | static void 8 | sig_alrm(int signo) 9 | { 10 | longjmp(env_alrm, 1); 11 | } 12 | 13 | unsigned int 14 | sleep2(unsigned int seconds) 15 | { 16 | if (signal(SIGALRM, sig_alrm) == SIG_ERR) 17 | return(seconds); 18 | if (setjmp(env_alrm) == 0) { 19 | alarm(seconds); /* start the timer */ 20 | pause(); /* next caught signal wakes us up */ 21 | } 22 | return(alarm(0)); /* turn off timer, return unslept time */ 23 | } 24 | -------------------------------------------------------------------------------- /apue/apue.3e/signals/suspend1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/signals/suspend1 -------------------------------------------------------------------------------- /apue/apue.3e/signals/suspend2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/signals/suspend2 -------------------------------------------------------------------------------- /apue/apue.3e/signals/systest2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/signals/systest2 -------------------------------------------------------------------------------- /apue/apue.3e/signals/systest2.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | static void 4 | sig_int(int signo) 5 | { 6 | printf("caught SIGINT\n"); 7 | } 8 | 9 | static void 10 | sig_chld(int signo) 11 | { 12 | printf("caught SIGCHLD\n"); 13 | } 14 | 15 | int 16 | main(void) 17 | { 18 | if (signal(SIGINT, sig_int) == SIG_ERR) 19 | err_sys("signal(SIGINT) error"); 20 | if (signal(SIGCHLD, sig_chld) == SIG_ERR) 21 | err_sys("signal(SIGCHLD) error"); 22 | if (system("/bin/ed") < 0) 23 | err_sys("system() error"); 24 | exit(0); 25 | } 26 | -------------------------------------------------------------------------------- /apue/apue.3e/signals/tsleep2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/signals/tsleep2 -------------------------------------------------------------------------------- /apue/apue.3e/sockets/clconn.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | #define MAXSLEEP 128 5 | 6 | int 7 | connect_retry(int sockfd, const struct sockaddr *addr, socklen_t alen) 8 | { 9 | int numsec; 10 | 11 | /* 12 | * Try to connect with exponential backoff. 13 | */ 14 | for (numsec = 1; numsec <= MAXSLEEP; numsec <<= 1) { 15 | if (connect(sockfd, addr, alen) == 0) { 16 | /* 17 | * Connection accepted. 18 | */ 19 | return(0); 20 | } 21 | 22 | /* 23 | * Delay before trying again. 24 | */ 25 | if (numsec <= MAXSLEEP/2) 26 | sleep(numsec); 27 | } 28 | return(-1); 29 | } 30 | -------------------------------------------------------------------------------- /apue/apue.3e/sockets/findsvc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/sockets/findsvc -------------------------------------------------------------------------------- /apue/apue.3e/sockets/initsrv1.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | #include 4 | 5 | int 6 | initserver(int type, const struct sockaddr *addr, socklen_t alen, 7 | int qlen) 8 | { 9 | int fd; 10 | int err = 0; 11 | 12 | if ((fd = socket(addr->sa_family, type, 0)) < 0) 13 | return(-1); 14 | if (bind(fd, addr, alen) < 0) 15 | goto errout; 16 | if (type == SOCK_STREAM || type == SOCK_SEQPACKET) { 17 | if (listen(fd, qlen) < 0) 18 | goto errout; 19 | } 20 | return(fd); 21 | 22 | errout: 23 | err = errno; 24 | close(fd); 25 | errno = err; 26 | return(-1); 27 | } 28 | -------------------------------------------------------------------------------- /apue/apue.3e/sockets/ruptime: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/sockets/ruptime -------------------------------------------------------------------------------- /apue/apue.3e/sockets/ruptime-dg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/sockets/ruptime-dg -------------------------------------------------------------------------------- /apue/apue.3e/sockets/ruptimed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/sockets/ruptimed -------------------------------------------------------------------------------- /apue/apue.3e/sockets/ruptimed-dg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/sockets/ruptimed-dg -------------------------------------------------------------------------------- /apue/apue.3e/sockets/ruptimed-fd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/sockets/ruptimed-fd -------------------------------------------------------------------------------- /apue/apue.3e/standards/conf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/standards/conf -------------------------------------------------------------------------------- /apue/apue.3e/standards/options: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/standards/options -------------------------------------------------------------------------------- /apue/apue.3e/standards/pathconf-lim.sym: -------------------------------------------------------------------------------- 1 | FILESIZEBITS _PC_FILESIZEBITS 2 | LINK_MAX _PC_LINK_MAX 3 | MAX_CANON _PC_MAX_CANON 4 | MAX_INPUT _PC_MAX_INPUT 5 | NAME_MAX _PC_NAME_MAX 6 | PATH_MAX _PC_PATH_MAX 7 | PIPE_BUF _PC_PIPE_BUF 8 | SYMLINK_MAX _PC_SYMLINK_MAX 9 | _POSIX_TIMESTAMP_RESOLUTION _PC_TIMESTAMP_RESOLUTION 10 | -------------------------------------------------------------------------------- /apue/apue.3e/standards/pathconf-opt.sym: -------------------------------------------------------------------------------- 1 | _POSIX_CHOWN_RESTRICTED _PC_CHOWN_RESTRICTED 2 | _POSIX_NO_TRUNC _PC_NO_TRUNC 3 | _POSIX_VDISABLE _PC_VDISABLE 4 | _POSIX_ASYNC_IO _PC_ASYNC_IO 5 | _POSIX_PRIO_IO _PC_PRIO_IO 6 | _POSIX_SYNC_IO _PC_SYNC_IO 7 | _POSIX2_SYMLINKS _PC_2_SYMLINKS 8 | -------------------------------------------------------------------------------- /apue/apue.3e/standards/pathconf.sym: -------------------------------------------------------------------------------- 1 | FILESIZEBITS _PC_FILESIZEBITS 2 | LINK_MAX _PC_LINK_MAX 3 | MAX_CANON _PC_MAX_CANON 4 | MAX_INPUT _PC_MAX_INPUT 5 | NAME_MAX _PC_NAME_MAX 6 | PATH_MAX _PC_PATH_MAX 7 | PIPE_BUF _PC_PIPE_BUF 8 | SYMLINK_MAX _PC_SYMLINK_MAX 9 | _POSIX_TIMESTAMP_RESOLUTION _PC_TIMESTAMP_RESOLUTION 10 | -------------------------------------------------------------------------------- /apue/apue.3e/standards/pathopt.sym: -------------------------------------------------------------------------------- 1 | _POSIX_CHOWN_RESTRICTED _PC_CHOWN_RESTRICTED 2 | _POSIX_NO_TRUNC _PC_NO_TRUNC 3 | _POSIX_VDISABLE _PC_VDISABLE 4 | _POSIX_ASYNC_IO _PC_ASYNC_IO 5 | _POSIX_PRIO_IO _PC_PRIO_IO 6 | _POSIX_SYNC_IO _PC_SYNC_IO 7 | _POSIX2_SYMLINKS _PC_2_SYMLINKS 8 | -------------------------------------------------------------------------------- /apue/apue.3e/stdio/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | ifeq "$(PLATFORM)" "linux" 6 | MEMSTR = memstr 7 | else 8 | MEMSTR = 9 | endif 10 | 11 | PROGS = buf fgetsfputs getcharbug getcputc mkstemp tempfiles 12 | 13 | all: $(PROGS) $(MEMSTR) 14 | 15 | %: %.c $(LIBAPUE) 16 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 17 | 18 | clean: 19 | rm -f $(PROGS) $(TEMPFILES) *.o $(MEMSTR) 20 | 21 | include $(ROOT)/Make.libapue.inc 22 | -------------------------------------------------------------------------------- /apue/apue.3e/stdio/buf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/stdio/buf -------------------------------------------------------------------------------- /apue/apue.3e/stdio/fgetsfputs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/stdio/fgetsfputs -------------------------------------------------------------------------------- /apue/apue.3e/stdio/fgetsfputs.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | char buf[MAXLINE]; 7 | 8 | while (fgets(buf, MAXLINE, stdin) != NULL) 9 | if (fputs(buf, stdout) == EOF) 10 | err_sys("output error"); 11 | 12 | if (ferror(stdin)) 13 | err_sys("input error"); 14 | 15 | exit(0); 16 | } 17 | -------------------------------------------------------------------------------- /apue/apue.3e/stdio/getcharbug: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/stdio/getcharbug -------------------------------------------------------------------------------- /apue/apue.3e/stdio/getcharbug.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int 4 | main(void) 5 | { 6 | char c; 7 | 8 | while ((c = getchar()) != EOF) 9 | putchar(c); 10 | } 11 | -------------------------------------------------------------------------------- /apue/apue.3e/stdio/getcputc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/stdio/getcputc -------------------------------------------------------------------------------- /apue/apue.3e/stdio/getcputc.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | int c; 7 | 8 | while ((c = getc(stdin)) != EOF) 9 | if (putc(c, stdout) == EOF) 10 | err_sys("output error"); 11 | 12 | if (ferror(stdin)) 13 | err_sys("input error"); 14 | 15 | exit(0); 16 | } 17 | -------------------------------------------------------------------------------- /apue/apue.3e/stdio/memstr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/stdio/memstr -------------------------------------------------------------------------------- /apue/apue.3e/stdio/mkstemp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/stdio/mkstemp -------------------------------------------------------------------------------- /apue/apue.3e/stdio/tempfiles: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/stdio/tempfiles -------------------------------------------------------------------------------- /apue/apue.3e/stdio/tempfiles.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | char name[L_tmpnam], line[MAXLINE]; 7 | FILE *fp; 8 | 9 | printf("%s\n", tmpnam(NULL)); /* first temp name */ 10 | 11 | tmpnam(name); /* second temp name */ 12 | printf("%s\n", name); 13 | 14 | if ((fp = tmpfile()) == NULL) /* create temp file */ 15 | err_sys("tmpfile error"); 16 | fputs("one line of output\n", fp); /* write to temp file */ 17 | rewind(fp); /* then read it back */ 18 | if (fgets(line, sizeof(line), fp) == NULL) 19 | err_sys("fgets error"); 20 | fputs(line, stdout); /* print the line we wrote */ 21 | 22 | exit(0); 23 | } 24 | -------------------------------------------------------------------------------- /apue/apue.3e/systype.sh: -------------------------------------------------------------------------------- 1 | # (leading space required for Xenix /bin/sh) 2 | 3 | # 4 | # Determine the type of *ix operating system that we're 5 | # running on, and echo an appropriate value. 6 | # This script is intended to be used in Makefiles. 7 | # (This is a kludge. Gotta be a better way.) 8 | # 9 | 10 | case `uname -s` in 11 | "FreeBSD") 12 | PLATFORM="freebsd" 13 | ;; 14 | "Linux") 15 | PLATFORM="linux" 16 | ;; 17 | "Darwin") 18 | PLATFORM="macos" 19 | ;; 20 | "SunOS") 21 | PLATFORM="solaris" 22 | ;; 23 | *) 24 | echo "Unknown platform" >&2 25 | exit 1 26 | esac 27 | echo $PLATFORM 28 | exit 0 29 | -------------------------------------------------------------------------------- /apue/apue.3e/termios/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | PROGS = csize settty t_getpass t_isatty t_raw t_ttyname winch 6 | 7 | all: $(PROGS) ctermid.o getpass.o isatty.o ttyname.o 8 | 9 | %: %.c $(LIBAPUE) 10 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 11 | 12 | clean: 13 | rm -f $(PROGS) $(TEMPFILES) *.o 14 | 15 | include $(ROOT)/Make.libapue.inc 16 | -------------------------------------------------------------------------------- /apue/apue.3e/termios/csize: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/termios/csize -------------------------------------------------------------------------------- /apue/apue.3e/termios/ctermid.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static char ctermid_name[L_ctermid]; 5 | 6 | char * 7 | ctermid(char *str) 8 | { 9 | if (str == NULL) 10 | str = ctermid_name; 11 | return(strcpy(str, "/dev/tty")); /* strcpy() returns str */ 12 | } 13 | -------------------------------------------------------------------------------- /apue/apue.3e/termios/isatty.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int 4 | isatty(int fd) 5 | { 6 | struct termios ts; 7 | 8 | return(tcgetattr(fd, &ts) != -1); /* true if no error (is a tty) */ 9 | } 10 | -------------------------------------------------------------------------------- /apue/apue.3e/termios/settty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/termios/settty -------------------------------------------------------------------------------- /apue/apue.3e/termios/t_getpass: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/termios/t_getpass -------------------------------------------------------------------------------- /apue/apue.3e/termios/t_getpass.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | char *getpass(const char *); 4 | 5 | int 6 | main(void) 7 | { 8 | char *ptr; 9 | 10 | if ((ptr = getpass("Enter password:")) == NULL) 11 | err_sys("getpass error"); 12 | printf("password: %s\n", ptr); 13 | 14 | /* now use password (probably encrypt it) ... */ 15 | 16 | while (*ptr != 0) 17 | *ptr++ = 0; /* zero it out when we're done with it */ 18 | exit(0); 19 | } 20 | -------------------------------------------------------------------------------- /apue/apue.3e/termios/t_isatty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/termios/t_isatty -------------------------------------------------------------------------------- /apue/apue.3e/termios/t_isatty.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | 3 | int 4 | main(void) 5 | { 6 | printf("fd 0: %s\n", isatty(0) ? "tty" : "not a tty"); 7 | printf("fd 1: %s\n", isatty(1) ? "tty" : "not a tty"); 8 | printf("fd 2: %s\n", isatty(2) ? "tty" : "not a tty"); 9 | exit(0); 10 | } 11 | -------------------------------------------------------------------------------- /apue/apue.3e/termios/t_raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/termios/t_raw -------------------------------------------------------------------------------- /apue/apue.3e/termios/t_ttyname: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/termios/t_ttyname -------------------------------------------------------------------------------- /apue/apue.3e/termios/winch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/termios/winch -------------------------------------------------------------------------------- /apue/apue.3e/threadctl/Makefile: -------------------------------------------------------------------------------- 1 | ROOT=.. 2 | PLATFORM=$(shell $(ROOT)/systype.sh) 3 | include $(ROOT)/Make.defines.$(PLATFORM) 4 | 5 | TOUT = 6 | ifeq "$(PLATFORM)" "freebsd" 7 | EXTRALIBS = -pthread 8 | endif 9 | ifeq "$(PLATFORM)" "linux" 10 | EXTRALIBS = -pthread 11 | TOUT = timeout.o 12 | endif 13 | ifeq "$(PLATFORM)" "solaris" 14 | EXTRALIBS = -lpthread 15 | TOUT = timeout.o 16 | endif 17 | 18 | PROGS = atfork suspend 19 | 20 | all: $(PROGS) detach.o getenv1.o getenv2.o getenv3.o $(TOUT) 21 | 22 | %: %.c $(LIBAPUE) 23 | $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS) $(LDLIBS) 24 | 25 | clean: 26 | rm -f $(PROGS) $(TEMPFILES) *.o 27 | 28 | include $(ROOT)/Make.libapue.inc 29 | -------------------------------------------------------------------------------- /apue/apue.3e/threadctl/atfork: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/threadctl/atfork -------------------------------------------------------------------------------- /apue/apue.3e/threadctl/detach.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #include 3 | 4 | int 5 | makethread(void *(*fn)(void *), void *arg) 6 | { 7 | int err; 8 | pthread_t tid; 9 | pthread_attr_t attr; 10 | 11 | err = pthread_attr_init(&attr); 12 | if (err != 0) 13 | return(err); 14 | err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 15 | if (err == 0) 16 | err = pthread_create(&tid, &attr, fn, arg); 17 | pthread_attr_destroy(&attr); 18 | return(err); 19 | } 20 | -------------------------------------------------------------------------------- /apue/apue.3e/threadctl/getenv1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define MAXSTRINGSZ 4096 5 | 6 | static char envbuf[MAXSTRINGSZ]; 7 | 8 | extern char **environ; 9 | 10 | char * 11 | getenv(const char *name) 12 | { 13 | int i, len; 14 | 15 | len = strlen(name); 16 | for (i = 0; environ[i] != NULL; i++) { 17 | if ((strncmp(name, environ[i], len) == 0) && 18 | (environ[i][len] == '=')) { 19 | strncpy(envbuf, &environ[i][len+1], MAXSTRINGSZ-1); 20 | return(envbuf); 21 | } 22 | } 23 | return(NULL); 24 | } 25 | -------------------------------------------------------------------------------- /apue/apue.3e/threadctl/suspend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/threadctl/suspend -------------------------------------------------------------------------------- /apue/apue.3e/threads/badexit2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/threads/badexit2 -------------------------------------------------------------------------------- /apue/apue.3e/threads/barrier: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/threads/barrier -------------------------------------------------------------------------------- /apue/apue.3e/threads/cleanup: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/threads/cleanup -------------------------------------------------------------------------------- /apue/apue.3e/threads/exitstatus: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/threads/exitstatus -------------------------------------------------------------------------------- /apue/apue.3e/threads/maketimeout.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | maketimeout(struct timespec *tsp, long minutes) 6 | { 7 | struct timeval now; 8 | 9 | /* get the current time */ 10 | gettimeofday(&now, NULL); 11 | tsp->tv_sec = now.tv_sec; 12 | tsp->tv_nsec = now.tv_usec * 1000; /* usec to nsec */ 13 | /* add the offset to get timeout value */ 14 | tsp->tv_sec += minutes * 60; 15 | } 16 | -------------------------------------------------------------------------------- /apue/apue.3e/threads/threadid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/threads/threadid -------------------------------------------------------------------------------- /apue/apue.3e/threads/timedlock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/apue.3e/threads/timedlock -------------------------------------------------------------------------------- /apue/src.3e.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/apue/src.3e.tar.gz -------------------------------------------------------------------------------- /code/05UnixunitStdIo/01MyEffectIo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/05UnixunitStdIo/01MyEffectIo -------------------------------------------------------------------------------- /code/05UnixunitStdIo/01MyEffectIo.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | int main(void) 3 | { 4 | int c; 5 | while((c=getc(stdin))!=EOF) 6 | { 7 | if(putc(c,stdout)==EOF) 8 | err_sys("output error"); 9 | } 10 | if(ferror(stdin)) 11 | err_sys("input error"); 12 | exit(0); 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /code/05UnixunitStdIo/02MyeffectioRdWr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/05UnixunitStdIo/02MyeffectioRdWr -------------------------------------------------------------------------------- /code/05UnixunitStdIo/02MyeffectioRdWr.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | int main(void) 3 | { 4 | char buf[MAXLINE]; 5 | while(fgets(buf,MAXLINE,stdin)!=NULL) 6 | if(fputs(buf,stdout)==EOF) 7 | err_sys("output error"); 8 | if(ferror(stdin)) 9 | err_sys("input error"); 10 | exit(0); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /code/05UnixunitStdIo/03MyIoStdio: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/05UnixunitStdIo/03MyIoStdio -------------------------------------------------------------------------------- /code/05UnixunitStdIo/04Mytempfile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/05UnixunitStdIo/04Mytempfile -------------------------------------------------------------------------------- /code/05UnixunitStdIo/04Mytempfile.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | int main(void) 3 | { 4 | char name[L_tmpnam],line[MAXLINE]; 5 | FILE*fp; 6 | printf("%s \n",tmpnam(NULL)); 7 | tmpnam(name); 8 | printf("%s\n",name); 9 | if((fp=tmpfile())==NULL) 10 | err_sys("tmpfile error"); 11 | fputs("one line of output \n",fp); 12 | rewind(fp); 13 | if(fgets(line,sizeof(line),fp)==NULL) 14 | err_sys("fgets error"); 15 | fputs(line,stdout);// print the line we wrote 16 | exit(0); 17 | } 18 | //每次产生不同的临时文件,但是临时文件对我们来说是不可兼得的,所以说是不安全的,对于ISO 从规范来说 ,建议使用它更安全的mkstemp函数。 19 | -------------------------------------------------------------------------------- /code/05UnixunitStdIo/05Mymsktemp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/05UnixunitStdIo/05Mymsktemp -------------------------------------------------------------------------------- /code/05UnixunitStdIo/065-14Memorystream: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/05UnixunitStdIo/065-14Memorystream -------------------------------------------------------------------------------- /code/05UnixunitStdIo/std.err: -------------------------------------------------------------------------------- 1 | one line to standard error 2 | -------------------------------------------------------------------------------- /code/05UnixunitStdIo/std.out: -------------------------------------------------------------------------------- 1 | enter any character : 2 | stream =stdin ,fully buffered, buffered size =4096 3 | stream =stdout ,fully buffered, buffered size =4096 4 | stream =stderr ,unbuffered, buffered size =1 5 | stream =/etc/passwd ,fully buffered, buffered size =4096 6 | -------------------------------------------------------------------------------- /code/06UnixunitsystemdateInfo/016-2Mygetpwnam.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | struct passwd*getpwnam(const char * name) 5 | { 6 | struct passwd *ptr; 7 | setpwent(); 8 | while((ptr=getpwent())!=NULL) 9 | if(strcmp(name,ptr->pw_name)==0) 10 | break; 11 | endpwent(); 12 | return (0); 13 | 14 | 15 | 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /code/06UnixunitsystemdateInfo/02Mygettime: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/06UnixunitsystemdateInfo/02Mygettime -------------------------------------------------------------------------------- /code/06UnixunitsystemdateInfo/02Mygettime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main(void) 5 | { 6 | time_t t; 7 | struct tm* mytime; 8 | char buf[16]; 9 | char buff[64]; 10 | time(&t); 11 | mytime=localtime(&t); 12 | if(strftime(buf,16,"time and date : %r ,%a %b %d, %Y",mytime)==0) 13 | printf("bufer length is too small\n"); 14 | else 15 | printf("%s\n", buf); 16 | if(strftime(buff,64,"time and date : %r ,%a %b %d, %Y",mytime)==0) 17 | printf("bufer length is too small\n"); 18 | else 19 | printf("%s\n",buff); 20 | exit(0); 21 | } 22 | -------------------------------------------------------------------------------- /code/06UnixunitsystemdateInfo/03Myuname: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/06UnixunitsystemdateInfo/03Myuname -------------------------------------------------------------------------------- /code/06UnixunitsystemdateInfo/03Myuname.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | #include 3 | #include 4 | int main(void) 5 | { 6 | int i; 7 | struct utsname myuname; 8 | if((i=uname(&myuname))<0) 9 | err_sys("uname error"); 10 | else 11 | printf("%s\t%s\t%s\t%s\t%s",myuname.sysname,myuname.nodename,myuname.version,myuname.release,myuname.machine); 12 | 13 | 14 | 15 | // char buf[64]; 16 | // if((gethostname(&buf,strlen(buf))<0) 17 | // err_sys("gethostname error"); 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | exit(0); 30 | } 31 | -------------------------------------------------------------------------------- /code/06UnixunitsystemdateInfo/06.2Myshadow: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/06UnixunitsystemdateInfo/06.2Myshadow -------------------------------------------------------------------------------- /code/06UnixunitsystemdateInfo/06.2Myshadow.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | #include 3 | int main(void) 4 | { 5 | struct spwd *ptr; 6 | if((ptr=getspnam("sar"))==NULL) 7 | err_sys("getspnam error"); 8 | printf("sp_ pwdp=%s\n",ptr->sp_pwdp==NULL||ptr->sp_pwdp[0]==0? "(null)" : ptr->sp_pwdp); 9 | 10 | 11 | 12 | exit(0); 13 | } 14 | -------------------------------------------------------------------------------- /code/07UnixunitForkEnv/01Myhelloworld: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/07UnixunitForkEnv/01Myhelloworld -------------------------------------------------------------------------------- /code/07UnixunitForkEnv/01Myhelloworld.c: -------------------------------------------------------------------------------- 1 | #include 2 | int f1(int val) 3 | { 4 | int num=0; 5 | int *ptr=# 6 | if(val==0) 7 | { 8 | int val=5; 9 | ptr=&val; 10 | } 11 | return (*ptr+1); 12 | } 13 | int main(void) 14 | { 15 | printf("hello world !\n"); 16 | printf("%d",f1(1)); 17 | exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /code/07UnixunitForkEnv/02Myexit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/07UnixunitForkEnv/02Myexit -------------------------------------------------------------------------------- /code/07UnixunitForkEnv/02Myexit.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | static void my_exit1(void); 3 | static void my_exit2(void); 4 | 5 | 6 | int main (void) 7 | { 8 | if(atexit(my_exit2)!=0) 9 | err_sys("can't register my_exit2)"); 10 | if(atexit(my_exit1)!=0) 11 | err_sys("can't register my_exit1"); 12 | if(atexit(my_exit1)!=0) 13 | err_sys("can't register my_exit1"); 14 | printf("main is done \n"); 15 | return 0; 16 | 17 | } 18 | 19 | static void my_exit1(void) 20 | { 21 | printf("first exit hander\n"); 22 | 23 | } 24 | static void my_exit2(void) 25 | { 26 | printf("second exit hander\n"); 27 | 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /code/07UnixunitForkEnv/03Myecho: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/07UnixunitForkEnv/03Myecho -------------------------------------------------------------------------------- /code/07UnixunitForkEnv/03Myecho.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | int main(int argc,char **argv,char ** envp) 3 | { 4 | int i; 5 | for(i=0;i0) 13 | exit(0); 14 | sleep(2); 15 | printf("second child ,parent pid =%ld\n, self pid=%ld\n",(long )getppid(),(long)getpid()); 16 | exit(0); 17 | } 18 | if(waitpid(pid ,NULL,0)!=pid) 19 | err_sys("waitpid error"); 20 | //we're the parent we continue executing ,knowing that we are not the parent of the second child 21 | 22 | 23 | 24 | exit(0); 25 | } 26 | -------------------------------------------------------------------------------- /code/08ForkContral/05-8-12MyIpc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/08ForkContral/05-8-12MyIpc -------------------------------------------------------------------------------- /code/08ForkContral/05-8-12MyIpc.c: -------------------------------------------------------------------------------- 1 | //To solve the race condition 解决竞争关系和轮询的情况 2 | //在unix中有专门的IPC通信或者管道符操作。 3 | #include"apue.h" 4 | static void charactatime(char *); 5 | int main(void) 6 | { 7 | pid_t pid ; 8 | if((pid= fork())<0) 9 | err_sys("fork error"); 10 | else if(pid==0) 11 | charactatime("output from child\n"); 12 | else 13 | charactatime("output from parent\n"); 14 | 15 | 16 | exit(0); 17 | } 18 | static void charactatime(char*str) 19 | { 20 | char *ptr; 21 | int c; 22 | setbuf(stdout,NULL); 23 | for(ptr=str;(c=*ptr++)!=0;) 24 | putc(c,stdout); 25 | } 26 | //竞争策略对于完善的linux系统来说已经完善的很好了,对于一些宏,或者函数也不再需要 27 | -------------------------------------------------------------------------------- /code/08ForkContral/06-8_13MyextendIPC: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/08ForkContral/06-8_13MyextendIPC -------------------------------------------------------------------------------- /code/08ForkContral/06-8_13MyextendIPC.c: -------------------------------------------------------------------------------- 1 | //To solve the race condition 解决竞争关系和轮询的情况 2 | //在unix中有专门的IPC通信或者管道符操作。 3 | #include"apue.h" 4 | static void charactatime(char *); 5 | int main(void) 6 | { 7 | pid_t pid ; 8 | TELL_WAIT(); 9 | if((pid= fork())<0) 10 | err_sys("fork error"); 11 | else if(pid==0) 12 | { 13 | charactatime("output from child\n"); 14 | WAIT_PARENT(); 15 | } 16 | else 17 | { 18 | charactatime("output from parent\n"); 19 | TELL_CHILD(pid); 20 | } 21 | 22 | exit(0); 23 | } 24 | static void charactatime(char*str) 25 | { 26 | char *ptr; 27 | int c; 28 | setbuf(stdout,NULL); 29 | for(ptr=str;(c=*ptr++)!=0;) 30 | putc(c,stdout); 31 | } 32 | -------------------------------------------------------------------------------- /code/08ForkContral/08-8_16Myexec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/08ForkContral/08-8_16Myexec -------------------------------------------------------------------------------- /code/08ForkContral/09-8-17Myechoall: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/08ForkContral/09-8-17Myechoall -------------------------------------------------------------------------------- /code/08ForkContral/09-8-17Myechoall.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | int main(int argc,char **argv,char ** env) 3 | { 4 | int i; 5 | char **ptr; 6 | for(i=0;i 2 | #include 3 | #include 4 | int mysystem(const char *cmdstring) 5 | { 6 | pid_t pid; 7 | int status; 8 | 9 | if((pid=fork())<0) 10 | { 11 | status =-1; 12 | 13 | } 14 | else if(pid==0) 15 | { 16 | execl("/bin/sh","sh","-c",cmdstring,(char *)0); 17 | _exit(127); 18 | } 19 | 20 | else 21 | { 22 | while(waitpid(pid,&status,0)<0) 23 | { 24 | status=-1; 25 | break; 26 | } 27 | } 28 | 29 | return (status); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /code/08ForkContral/12-8_23MytestSystem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/08ForkContral/12-8_23MytestSystem -------------------------------------------------------------------------------- /code/08ForkContral/12-8_23MytestSystem.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | #include 3 | int main(int argc,char ** argv) 4 | { 5 | int status; 6 | if((status=system("date"))<0) 7 | err_sys("system() error"); 8 | pr_exit(status); 9 | if((status=system("nosuchcommand"))<0) 10 | err_sys("system() error"); 11 | pr_exit(status); 12 | if((status=system("who ;exit 44"))<0) 13 | err_sys("system() error"); 14 | pr_exit(status); 15 | exit(0); 16 | 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /code/08ForkContral/13-8-24MycommandSystem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/08ForkContral/13-8-24MycommandSystem -------------------------------------------------------------------------------- /code/08ForkContral/13-8-24MycommandSystem.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | int main(int argc,char **argv) 3 | { 4 | int status; 5 | if(argc<2) 6 | err_quit("command-line argument required"); 7 | if((status=system(argv[1]))<0) 8 | err_sys("system() error"); 9 | pr_exit(status); 10 | exit(0); 11 | } 12 | -------------------------------------------------------------------------------- /code/08ForkContral/14-08_28MyProcessAccount: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/08ForkContral/14-08_28MyProcessAccount -------------------------------------------------------------------------------- /code/08ForkContral/15-08_29MyTestProcessAccount: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/08ForkContral/15-08_29MyTestProcessAccount -------------------------------------------------------------------------------- /code/08ForkContral/16-08_30Mynice: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/08ForkContral/16-08_30Mynice -------------------------------------------------------------------------------- /code/08ForkContral/17-08_31MyTmsShell: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/08ForkContral/17-08_31MyTmsShell -------------------------------------------------------------------------------- /code/08ForkContral/18-MyZombieofork: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/08ForkContral/18-MyZombieofork -------------------------------------------------------------------------------- /code/08ForkContral/18-MyZombieofork.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | #define PSCMD "ps -o pid,ppid,state,tty,command" 3 | int main(void) 4 | { 5 | pid_t pid; 6 | if((pid=fork())<0) 7 | err_sys("fork error"); 8 | else if(pid==0) 9 | exit(0); 10 | //父进程 11 | sleep(4); 12 | system(PSCMD); 13 | exit(0); 14 | } 15 | -------------------------------------------------------------------------------- /code/09Forkresulation/01-09_12MyOrphanProcess: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/09Forkresulation/01-09_12MyOrphanProcess -------------------------------------------------------------------------------- /code/09Forkresulation/9.1practice.md: -------------------------------------------------------------------------------- 1 | ###?考虑6.8节中说明的utmp和wtmp文件,为什么logout记录是由init进程写入的?对于网络登录的原理是否相同? 2 | 3 | ``` 4 | 这个是这样的,因为init是登录shell的父进程,当登录shell终止时他收到SIGCHLD信号量,所以init进程知道什么时候 5 | 终端用户注销。 6 | 网络登录没有包含init在utmp文件和wtmp文件的登录项和相应的注销项是由一个处理登录并检测注销的进程写的。一般是 initd、telnetd等守护进程 7 | ``` 8 | -------------------------------------------------------------------------------- /code/09Forkresulation/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/09Forkresulation/a.out -------------------------------------------------------------------------------- /code/09Forkresulation/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/09Forkresulation/main.c -------------------------------------------------------------------------------- /code/09Forkresulation/makefile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/09Forkresulation/makefile -------------------------------------------------------------------------------- /code/09Forkresulation/temp.foo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/09Forkresulation/temp.foo -------------------------------------------------------------------------------- /code/10Signal/01MyexternSignal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/10Signal/01MyexternSignal -------------------------------------------------------------------------------- /code/10Signal/02-1MyTrafficcontral: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/10Signal/02-1MyTrafficcontral -------------------------------------------------------------------------------- /code/10Signal/03-10_2Mysignal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/10Signal/03-10_2Mysignal -------------------------------------------------------------------------------- /code/10Signal/10-10_23MySigsuspendWait: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/10Signal/10-10_23MySigsuspendWait -------------------------------------------------------------------------------- /code/10Signal/13-10_26MysystemEd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/10Signal/13-10_26MysystemEd -------------------------------------------------------------------------------- /code/10Signal/15-10_31MySignalContral: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/10Signal/15-10_31MySignalContral -------------------------------------------------------------------------------- /code/10Signal/2-10_5MySIGALARMsignal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/10Signal/2-10_5MySIGALARMsignal -------------------------------------------------------------------------------- /code/10Signal/2-10_5MySIGALARMsignal.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | #include 3 | 4 | static void my_alarm(int signo) 5 | { 6 | struct passwd * rootptr; 7 | printf("int the signal function \n"); 8 | if((rootptr=getpwnam("root"))==NULL) 9 | err_sys("getpwnam(root) error\n"); 10 | alarm(1); 11 | } 12 | 13 | 14 | int main(void) 15 | { 16 | struct passwd *ptr; 17 | signal(SIGALRM,my_alarm); 18 | alarm(1); 19 | for(;;) 20 | { 21 | if((ptr=getpwnam("victor"))==NULL) 22 | err_sys("getpwnam(victor) error\n"); 23 | if(strcmp(ptr->pw_name,"victor")!=0) 24 | printf("return value corrupted!,pw_name=%s\n",ptr->pw_name); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /code/10Signal/3-10MySIGCHLD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/10Signal/3-10MySIGCHLD -------------------------------------------------------------------------------- /code/10Signal/3-10_6MySIGCLD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/10Signal/3-10_6MySIGCLD -------------------------------------------------------------------------------- /code/10Signal/4-10.7.8.9MySIGALRM: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/10Signal/4-10.7.8.9MySIGALRM -------------------------------------------------------------------------------- /code/10Signal/5-10_10Myalarm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/10Signal/5-10_10Myalarm -------------------------------------------------------------------------------- /code/10Signal/6-10MyalarmLongjmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/10Signal/6-10MyalarmLongjmp -------------------------------------------------------------------------------- /code/10Signal/7-10.11MySignalSet: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/10Signal/7-10.11MySignalSet -------------------------------------------------------------------------------- /code/10Signal/8-10_20.19.18MySetjmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/10Signal/8-10_20.19.18MySetjmp -------------------------------------------------------------------------------- /code/10Signal/9-10-22MySigsuspend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/10Signal/9-10-22MySigsuspend -------------------------------------------------------------------------------- /code/10Signal/changeSystem.md: -------------------------------------------------------------------------------- 1 | ##告诉自己从这里开始更改了系统盘为centos,不在使用unbutu 2 | - 原因是以内unbutu内核有点奇怪,在做信号这章的实验时出现的问题,让人很莫名其妙,在centos,redhat fedroa debin系列的linux系统下运行良好,所以才去centos系统 3 | -------------------------------------------------------------------------------- /code/10Signal/log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/10Signal/log -------------------------------------------------------------------------------- /code/10Signal/temp.foo: -------------------------------------------------------------------------------- 1 | hello,world,right 2 | -------------------------------------------------------------------------------- /code/11UnixUnitThread/01-11_2MyThreadCreate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/11UnixUnitThread/01-11_2MyThreadCreate -------------------------------------------------------------------------------- /code/11UnixUnitThread/11-11_16MyTasksPthreadSort: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/11UnixUnitThread/11-11_16MyTasksPthreadSort -------------------------------------------------------------------------------- /code/11UnixUnitThread/2-11_3MyThreadExit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/11UnixUnitThread/2-11_3MyThreadExit -------------------------------------------------------------------------------- /code/11UnixUnitThread/3-11_4MyPthread_exitwrong: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/11UnixUnitThread/3-11_4MyPthread_exitwrong -------------------------------------------------------------------------------- /code/11UnixUnitThread/4-11_5MyPthreadCleanProgram: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/11UnixUnitThread/4-11_5MyPthreadCleanProgram -------------------------------------------------------------------------------- /code/11UnixUnitThread/8-11_13_Mypthread_mutex_timedlock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/11UnixUnitThread/8-11_13_Mypthread_mutex_timedlock -------------------------------------------------------------------------------- /code/12UnixUnitThreadAttr/.02-12_4MySpecStatusCreatePthread.c.swo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/12UnixUnitThreadAttr/.02-12_4MySpecStatusCreatePthread.c.swo -------------------------------------------------------------------------------- /code/12UnixUnitThreadAttr/.02-12_4MySpecStatusCreatePthread.c.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/12UnixUnitThreadAttr/.02-12_4MySpecStatusCreatePthread.c.swp -------------------------------------------------------------------------------- /code/12UnixUnitThreadAttr/01MyThreadSide: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/12UnixUnitThreadAttr/01MyThreadSide -------------------------------------------------------------------------------- /code/12UnixUnitThreadAttr/02-12_4MySpecStatusCreatePthread: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/12UnixUnitThreadAttr/02-12_4MySpecStatusCreatePthread -------------------------------------------------------------------------------- /code/12UnixUnitThreadAttr/06-2_16MymutexSignalPthread: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/12UnixUnitThreadAttr/06-2_16MymutexSignalPthread -------------------------------------------------------------------------------- /code/12UnixUnitThreadAttr/07-12_17MyPthread_atfork: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/12UnixUnitThreadAttr/07-12_17MyPthread_atfork -------------------------------------------------------------------------------- /code/12UnixUnitThreadAttr/7-12_17.txt: -------------------------------------------------------------------------------- 1 | thread started.... 2 | parent about t ofork ... 3 | preparing locks .. 4 | parent unlocking locks .. 5 | parent return from fork 6 | thread started.... 7 | parent about t ofork ... 8 | preparing locks .. 9 | child unlocking locks .. 10 | child return from fork 11 | -------------------------------------------------------------------------------- /code/13UnixUnitDaemonFork/01-13_1MyinitDaemonFork: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/13UnixUnitDaemonFork/01-13_1MyinitDaemonFork -------------------------------------------------------------------------------- /code/13UnixUnitDaemonFork/03-13_7MyDaemonSecond: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/13UnixUnitDaemonFork/03-13_7MyDaemonSecond -------------------------------------------------------------------------------- /code/13UnixUnitDaemonFork/04-13_8MyPthreadGetSignalConf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/13UnixUnitDaemonFork/04-13_8MyPthreadGetSignalConf -------------------------------------------------------------------------------- /code/13UnixUnitDaemonFork/05-13_9Mysetckoexec.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: 05-13_9Mysetckoexec.c 3 | > Author:Victor Qi 4 | > Mail:Victor_QiGetFuture@163.com 5 | > Created Time: Mon 22 Feb 2016 01:53:37 AM CST 6 | ************************************************************************/ 7 | 8 | #include "apue.h" 9 | #include 10 | int set_cloexec(int fd) 11 | { 12 | int val; 13 | if((val=fcntl(fd,F_GETFD,0))<0) 14 | return -1; 15 | val |=FD_CLOEXEC; 16 | return(fcntl(fd,F_SETFD,val)); 17 | } 18 | -------------------------------------------------------------------------------- /code/13UnixUnitDaemonFork/readme.md: -------------------------------------------------------------------------------- 1 | ##对于守护进程 2 | - 其作用就是为系统服务,做守护,单方面讲就是让其成为系统进程,只要系统运行,服务无就会一直开启 3 | 因为守护进程是一直在目录底下运行的 , 4 | - 其要成为守护进程,必须成为孤儿进程,但是呢,又不会被杀死,工作目录切换到/ 下,去掉终端显示。成为孤傲的守护进程 5 | -------------------------------------------------------------------------------- /code/14UnixUnitAdvancedIO/01-14_1MyNoBlockIo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/14UnixUnitAdvancedIO/01-14_1MyNoBlockIo -------------------------------------------------------------------------------- /code/14UnixUnitAdvancedIO/01stderr.file: -------------------------------------------------------------------------------- 1 | read 50000 bytes 2 | nwrite=50000,errno=0 3 | fcntl F_SETFL error: Invalid argument 4 | -------------------------------------------------------------------------------- /code/14UnixUnitAdvancedIO/04-14_7MyDiedLock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/14UnixUnitAdvancedIO/04-14_7MyDiedLock -------------------------------------------------------------------------------- /code/14UnixUnitAdvancedIO/06-.lock: -------------------------------------------------------------------------------- 1 | abcdef -------------------------------------------------------------------------------- /code/14UnixUnitAdvancedIO/06-14_12MyConfirmLockSystem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/14UnixUnitAdvancedIO/06-14_12MyConfirmLockSystem -------------------------------------------------------------------------------- /code/14UnixUnitAdvancedIO/07-14_20MyTransFile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/14UnixUnitAdvancedIO/07-14_20MyTransFile -------------------------------------------------------------------------------- /code/14UnixUnitAdvancedIO/07_testone.md: -------------------------------------------------------------------------------- 1 | . 2 | .. 3 | 01-14_1MyNoBlockIo 4 | 01-14_1MyNoBlockIo.c 5 | 01stderr.file 6 | 01temp.file 7 | 0214_5MyAccReleaseLock.c 8 | 04-14_7MyDiedLock 9 | 04-14_7MyDiedLock.c 10 | 05-14_9Myloocfile.c 11 | 06-14_12MyConfirmLockSystem 12 | 06-14_12MyConfirmLockSystem.c 13 | 06-.lock 14 | 07-14_20MyTransFile 15 | 07-14_20MyTransFile.c 16 | 07_testone.md 17 | 07_testtwo.md 18 | templock 19 | _testone.md 20 | -------------------------------------------------------------------------------- /code/14UnixUnitAdvancedIO/07_testtwo.md: -------------------------------------------------------------------------------- 1 | . 2 | .. 3 | 01-14_1ZlAbOybpxVb 4 | 01-14_1ZlAbOybpxVb.p 5 | 01fgqree.svyr 6 | 01grzc.svyr 7 | 0214_5ZlNppEryrnfrYbpx.p 8 | 04-14_7ZlQvrqYbpx 9 | 04-14_7ZlQvrqYbpx.p 10 | 05-14_9Zlybbpsvyr.p 11 | 06-14_12ZlPbasvezYbpxFlfgrz 12 | 06-14_12ZlPbasvezYbpxFlfgrz.p 13 | 06-.ybpx 14 | 07-14_20ZlGenafSvyr 15 | 07-14_20ZlGenafSvyr.p 16 | 07_grfgbar.zq 17 | 07_grfggjb.zq 18 | grzcybpx 19 | _grfgbar.zq 20 | -------------------------------------------------------------------------------- /code/14UnixUnitAdvancedIO/08-14_21MyAsynchronousIO: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/14UnixUnitAdvancedIO/08-14_21MyAsynchronousIO -------------------------------------------------------------------------------- /code/14UnixUnitAdvancedIO/10-14_27MyMemory-mappedIO: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/14UnixUnitAdvancedIO/10-14_27MyMemory-mappedIO -------------------------------------------------------------------------------- /code/14UnixUnitAdvancedIO/14_Homework01: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/14UnixUnitAdvancedIO/14_Homework01 -------------------------------------------------------------------------------- /code/14UnixUnitAdvancedIO/_testone.md: -------------------------------------------------------------------------------- 1 | . 2 | .. 3 | 01-14_1MyNoBlockIo 4 | 01-14_1MyNoBlockIo.c 5 | 01stderr.file 6 | 01temp.file 7 | 0214_5MyAccReleaseLock.c 8 | 04-14_7MyDiedLock 9 | 04-14_7MyDiedLock.c 10 | 05-14_9Myloocfile.c 11 | 06-14_12MyConfirmLockSystem 12 | 06-14_12MyConfirmLockSystem.c 13 | 06-.lock 14 | 07-14_20MyTransFile 15 | 07-14_20MyTransFile.c 16 | 07_testtwo.md 17 | templock 18 | _testone.md 19 | -------------------------------------------------------------------------------- /code/14UnixUnitAdvancedIO/lockfile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/14UnixUnitAdvancedIO/lockfile -------------------------------------------------------------------------------- /code/14UnixUnitAdvancedIO/readme.md: -------------------------------------------------------------------------------- 1 | ##高级IO 2 | - 本章含有众多概念和函数,我们把它们都统统归类为高级IO。 3 | - 其中包括非阻塞IO、记录锁、IO多路转换就是我们常说的IO多路复用技术的基础 4 | - select和poll函数、异步IO、readv和writev函数以及存储映射IO(mmap). 5 | - 在后续15章和第17章的进程间通信以及以后各章节的实例都要使用本章所描述的概念和函数 6 | 7 | 8 | # 出自APUE第十四章高级IO部分 9 | `let's coding now!!` 10 | -------------------------------------------------------------------------------- /code/14UnixUnitAdvancedIO/templock: -------------------------------------------------------------------------------- 1 | ab -------------------------------------------------------------------------------- /code/15UnixUnitIPC/01-15_5MyParent2ChildForkIPC: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/15UnixUnitIPC/01-15_5MyParent2ChildForkIPC -------------------------------------------------------------------------------- /code/15UnixUnitIPC/02-15_6MyPipeDeparPage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/15UnixUnitIPC/02-15_6MyPipeDeparPage -------------------------------------------------------------------------------- /code/15UnixUnitIPC/04-15_6MyPopenOveriedCp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/15UnixUnitIPC/04-15_6MyPopenOveriedCp -------------------------------------------------------------------------------- /code/15UnixUnitIPC/06-15_14MySimpleCp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/15UnixUnitIPC/06-15_14MySimpleCp -------------------------------------------------------------------------------- /code/15UnixUnitIPC/07-15_15MyExternPopenGetFileToExec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/15UnixUnitIPC/07-15_15MyExternPopenGetFileToExec -------------------------------------------------------------------------------- /code/15UnixUnitIPC/08-15_17MyCoprocess: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/15UnixUnitIPC/08-15_17MyCoprocess -------------------------------------------------------------------------------- /code/15UnixUnitIPC/09-15_18MyCoprocessApplication: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/15UnixUnitIPC/09-15_18MyCoprocessApplication -------------------------------------------------------------------------------- /code/15UnixUnitIPC/11-15_31MyPrintMemAddr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/15UnixUnitIPC/11-15_31MyPrintMemAddr -------------------------------------------------------------------------------- /code/15UnixUnitIPC/12-15_33MyIPCSharedMemUse_dev_zero: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/15UnixUnitIPC/12-15_33MyIPCSharedMemUse_dev_zero -------------------------------------------------------------------------------- /code/15UnixUnitIPC/readme.md: -------------------------------------------------------------------------------- 1 | ##历经波折到了IPC通信 2 | - 1、对于IPC通信,相信大家已经耳熟能详了,因为在日常linux的使用中,我们用了大量的通信机制 3 | - 2、管道:经常见吧 ‘| ’就是这个符号,但是管道也分为半双工管道。 全双工管道(目测大多数由 4 | 域套接字来支持,有的用管道和域套接字共同支持) 5 | - 3、对于命名全双工管道,在SUS中被废弃,其他体系的系统支持 6 | - 4、XSI消息队列 XSI信号量 XSI共享存储 7 | - 5、消息队列(实时),信号量 共享存储(实时) 8 | - 6、套接字都支持 但是对于STREAMS 所有标准的类unix系统 均已废除这一机制 9 | 10 | ####不多说了,有点兴奋,开始吧 11 | -------------------------------------------------------------------------------- /code/15UnixUnitIPC/slock.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: slock.h 3 | > Author:Victor Qi 4 | > Mail:Victor_QiGetFuture@163.com 5 | > Created Time: Sun 21 Feb 2016 04:12:26 PM CST 6 | ************************************************************************/ 7 | 8 | #ifndef _SLOCK_H 9 | #define _SLOCK_H 10 | #include 11 | 12 | 13 | struct slock 14 | { 15 | sem_t *semp; 16 | char name[_POSIX_NAME_MAX]; 17 | }; 18 | #endif 19 | -------------------------------------------------------------------------------- /code/16UnixUnitInterIPCsocket/01-16_9MyGetaddrinfoHowToUse: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/16UnixUnitInterIPCsocket/01-16_9MyGetaddrinfoHowToUse -------------------------------------------------------------------------------- /code/16UnixUnitInterIPCsocket/05-16_16MyGetSeverTime: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/16UnixUnitInterIPCsocket/05-16_16MyGetSeverTime -------------------------------------------------------------------------------- /code/16UnixUnitInterIPCsocket/06-_17MyPostClientTime: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/16UnixUnitInterIPCsocket/06-_17MyPostClientTime -------------------------------------------------------------------------------- /code/16UnixUnitInterIPCsocket/readme.md: -------------------------------------------------------------------------------- 1 | #网络IPC:套接字 2 | 3 | 4 | - 对于上一张我们学了经典的多进程通信机制IPC:管道 、FIFO有名管道、消息队列、信号量、以及共享存储 5 | - 这些队列允许在同一台计算机上运行的进程可以互相通信。 6 | - 但是在本章 7 | ##Scoket 8 | - 通过网络连接来使得不同计算机上的进程相互通信。网络进程间通信(Network IPC).一个拉风的名字 9 | - 在本章中,我们将描述桃姐在网络进程件通信接口,进程用该接口能够和其他进程通信,无论他们是在同一计算机内,还是在不同的计算机上。 10 | - 实际上这就是网络套接字的设计目标之一,同样的接口既可以用于计算机间通信。也可以用于计算机内通信。 11 | - 尽管套接字接口可以采用不同的网络协议进行通信,但本章的讨论限制在因特网事实上的通信标准。TCP/IP协议栈。 12 | 13 | -------------------------------------------------------------------------------- /code/GetEnv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/GetEnv -------------------------------------------------------------------------------- /code/GetEnv.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(int argc,char **argv,char **env) 4 | { 5 | while(env&&*env) 6 | { 7 | cout<<*env< 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | char *env="USER_HOME"; 8 | putenv("USER_HOME=/user/root"); 9 | char *a=getenv(env); 10 | if(a!=NULL) 11 | cout<<"env :"< 2 | #include"apue.h" 3 | //#include 4 | //#include 5 | //#include 6 | #include 7 | //#include//这个文件不可用 8 | int main(int argc,char **argv) 9 | { 10 | DIR *dp; 11 | struct dirent *dirp; 12 | if(argc!=2) 13 | err_quit("usage:ls directory_name"); 14 | // printf("error"); 15 | if((dp=opendir(argv[1]))==NULL) 16 | err_sys("can't open %s",argv[1]); 17 | // printf("can't open %s",argv[1]); 18 | while((dirp=readdir(dp))!=NULL) 19 | printf("%s\n",dirp->d_name); 20 | closedir(dp); 21 | exit(0); 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /code/UnixUnit01/Dirls.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnit01/Dirls.o -------------------------------------------------------------------------------- /code/UnixUnit01/MyCopy.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | int main(int argc,char **argv) 3 | { 4 | int c; 5 | while((c=getc(stdin))!=EOF) 6 | { 7 | if(putc(c,stdout)==EOF) 8 | err_sys("output error"); 9 | } 10 | if(ferror(stdin)) 11 | err_sys("input error"); 12 | 13 | 14 | 15 | exit(0); 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /code/UnixUnit01/MyCopy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnit01/MyCopy.o -------------------------------------------------------------------------------- /code/UnixUnit01/MyPrintuserid.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | int main(void) 3 | { 4 | printf("uid=%d gid=%d \n",getuid(),getgid()); 5 | exit(0); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /code/UnixUnit01/MyPrintuserid.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnit01/MyPrintuserid.o -------------------------------------------------------------------------------- /code/UnixUnit01/MyShell.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnit01/MyShell.o -------------------------------------------------------------------------------- /code/UnixUnit01/MyShell01singal.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnit01/MyShell01singal.o -------------------------------------------------------------------------------- /code/UnixUnit01/Myerror.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | #include 3 | int main (int argc,char ** argv) 4 | { 5 | fprintf(stderr,"EACCESS :%s\n",strerror(EACCES)); 6 | errno=ENOENT; 7 | perror(argv[0]); 8 | exit(0); 9 | } 10 | -------------------------------------------------------------------------------- /code/UnixUnit01/Myerror.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnit01/Myerror.o -------------------------------------------------------------------------------- /code/UnixUnit01/Myfock.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | int main(int argc,char ** argv) 3 | { 4 | printf("hello world from process Id %ld\n",(long)getpid()); 5 | exit(0); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /code/UnixUnit01/Myfork.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnit01/Myfork.o -------------------------------------------------------------------------------- /code/UnixUnit01/Myio.c: -------------------------------------------------------------------------------- 1 | #include "apue.h" 2 | #define BUFFSIZE 4096 3 | int main(void) 4 | { 5 | int n; 6 | char buf[BUFFSIZE]; 7 | while((n=read(STDIN_FILENO,buf,BUFFSIZE))>0) 8 | { 9 | if(write(STDOUT_FILENO,buf,n)!=n) 10 | err_sys("write error"); 11 | } 12 | if(n<0) 13 | err_sys("read error"); 14 | exit(0); 15 | } 16 | -------------------------------------------------------------------------------- /code/UnixUnit01/Myio.data: -------------------------------------------------------------------------------- 1 | sad 2 | asda 3 | ds 4 | ad 5 | a 6 | d 7 | -------------------------------------------------------------------------------- /code/UnixUnit01/Myio.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnit01/Myio.o -------------------------------------------------------------------------------- /code/UnixUnit01/Test*++.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: Test*++.c 3 | > Author:Victor Qi 4 | > Mail:Victor_QiGetFuture@163.com 5 | > Created Time: Wed 02 Mar 2016 01:00:43 AM CST 6 | ************************************************************************/ 7 | #include 8 | int main(void) 9 | { 10 | char *ptr="Linux"; 11 | printf("%c",*ptr++); 12 | printf("%c",*ptr); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /code/UnixUnitIO03/MyCreatemptyio: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnitIO03/MyCreatemptyio -------------------------------------------------------------------------------- /code/UnixUnitIO03/MyCreatemptyio.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | #include 3 | char buf1[]="qwertyuiop"; 4 | char buf2[]="QWERTYUIOP"; 5 | int main(void) 6 | { 7 | int fd; 8 | if((fd=creat("myfile.txt",FILE_MODE))<0) 9 | err_sys("creat error"); 10 | if(write(fd,buf1,10)!=10) 11 | err_sys("write error"); 12 | if(lseek(fd,16384,SEEK_SET)==-1) 13 | err_sys("lseek error"); 14 | if(write (fd ,buf2,10)!=10) 15 | err_sys("write error"); 16 | 17 | 18 | 19 | 20 | //创建一个空洞文件,空洞文件是多线程的支持点之一,因为空洞文件的存在才能支持多线程断点续传 21 | 22 | 23 | exit(0); 24 | 25 | 26 | 27 | 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /code/UnixUnitIO03/MyCreatio.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | #include"fcntl.h" 3 | int main(int argc,char ** argv) 4 | { 5 | FILE *fp="./Mycreat.txt" 6 | creat(fp,"w+"); 7 | 8 | 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /code/UnixUnitIO03/MyEffectio: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnitIO03/MyEffectio -------------------------------------------------------------------------------- /code/UnixUnitIO03/MyEffectio.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | #define BUFFSIZE 4096 3 | int main(void) 4 | { 5 | int n; 6 | char buff[BUFFSIZE]; 7 | while((n=read(STDIN_FILENO,buff,BUFFSIZE))>0) 8 | { 9 | if(write(STDOUT_FILENO,buff,n)!=n) 10 | err_sys("write error"); 11 | } 12 | if(n<0) 13 | err_sys("read error"); 14 | exit(0); 15 | } 16 | -------------------------------------------------------------------------------- /code/UnixUnitIO03/MyFileioAnnoce: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnitIO03/MyFileioAnnoce -------------------------------------------------------------------------------- /code/UnixUnitIO03/MyStdio: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnitIO03/MyStdio -------------------------------------------------------------------------------- /code/UnixUnitIO03/MyStdio.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main (void) 4 | { 5 | putchar('a'); 6 | write(1, "b", 1); 7 | putchar('a'); 8 | write(1, "b", 1); 9 | putchar('a'); 10 | write(1, "b", 1); 11 | printf("\n"); 12 | return 0; 13 | } 14 | //window 下生成ababab 15 | //linux下是bbbaaa 16 | -------------------------------------------------------------------------------- /code/UnixUnitIO03/Myoffsetio: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnitIO03/Myoffsetio -------------------------------------------------------------------------------- /code/UnixUnitIO03/Myoffsetio.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | #include 3 | int main(void) 4 | { 5 | if(lseek(STDIN_FILENO,0,SEEK_CUR)==-1) 6 | printf("cannot seek\n"); 7 | else 8 | printf("seek ok\n"); 9 | exit(0); 10 | 11 | 12 | } 13 | -------------------------------------------------------------------------------- /code/UnixUnitIO03/file: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnitIO03/file -------------------------------------------------------------------------------- /code/UnixUnitIO04/10Mydev: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnitIO04/10Mydev -------------------------------------------------------------------------------- /code/UnixUnitIO04/10Mydev.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | #ifdef SOLARIS 3 | #include 4 | #endif 5 | #include 6 | int main(int argc,char **argv) 7 | { 8 | int i; 9 | struct stat buf; 10 | for(i =1;i 3 | int main(int argc, char ** argv) 4 | { 5 | if(argc!=2) 6 | err_quit("\tusage:%s ",argv[0]); 7 | if(access(argv[1],R_OK)<0) 8 | err_ret("\taccess error for %s",argv[1]); 9 | else 10 | printf(" \tread access OK\n"); 11 | if(open(argv[1],O_RDONLY)<0) 12 | err_ret("\topen error for %s",argv[1]); 13 | else 14 | printf("\topen for reading OK \n"); 15 | exit(0); 16 | } 17 | -------------------------------------------------------------------------------- /code/UnixUnitIO04/Mychdir08: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnitIO04/Mychdir08 -------------------------------------------------------------------------------- /code/UnixUnitIO04/Mychdir08.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | #include 3 | int main(void) 4 | { 5 | if(chdir("/tmp")<0) 6 | err_sys("chdir error"); 7 | printf("chdir to /tmp successed\n"); 8 | exit(0); 9 | 10 | 11 | 12 | 13 | 14 | } 15 | -------------------------------------------------------------------------------- /code/UnixUnitIO04/Mychmodio: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnitIO04/Mychmodio -------------------------------------------------------------------------------- /code/UnixUnitIO04/Mychmodio.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | 3 | 4 | int main(int argc , char** argv) 5 | { 6 | struct stat buf; 7 | if(stat("foo",&buf)<0) 8 | err_sys("stat error for foo"); 9 | if(chmod("foo",(buf.st_mode & ~S_IXGRP)|S_ISGID)<0) 10 | err_sys("chmod error for foo"); 11 | 12 | 13 | if(chmod("bar",S_IRUSR|S_IWUSR|S_IRWXG)<0) 14 | err_sys("chmod error for bar"); 15 | 16 | exit(0); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /code/UnixUnitIO04/Myfutimes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnitIO04/Myfutimes -------------------------------------------------------------------------------- /code/UnixUnitIO04/Myfutimes.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | #include 3 | int main(int argc,char **argv) 4 | { 5 | int i,fd; 6 | struct stat buf; 7 | struct timespec times[2]; 8 | for(i=1;i 3 | int main(int argc ,char **argv) 4 | { 5 | if(open("tempfile",O_RDWR)<0) 6 | err_sys("open tempfile file faied"); 7 | if(unlink("tempfile")<0) 8 | err_sys("unlink error"); 9 | printf("file unlinked \n"); 10 | sleep(10); 11 | printf("done\n"); 12 | exit(0); 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /code/UnixUnitIO04/Myumask: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnitIO04/Myumask -------------------------------------------------------------------------------- /code/UnixUnitIO04/Myumask.c: -------------------------------------------------------------------------------- 1 | #include"apue.h" 2 | #include 3 | #define RWRWRW (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) 4 | int main(int argc , char ** argv) 5 | { 6 | umask(0); 7 | if(creat("foo",RWRWRW)<0) 8 | err_sys("creat error for foo"); 9 | umask(S_IRUSR|S_IWUSR|S_IXUSR|S_IROTH|S_IWOTH); 10 | if(creat("bar",RWRWRW)<0) 11 | err_sys("create error for bar"); 12 | exit(0); 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /code/UnixUnitIO04/bar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnitIO04/bar -------------------------------------------------------------------------------- /code/UnixUnitIO04/foo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnitIO04/foo -------------------------------------------------------------------------------- /code/UnixUnitIO04/testln/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/UnixUnitIO04/testln/a -------------------------------------------------------------------------------- /code/epolldir/Client: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/epolldir/Client -------------------------------------------------------------------------------- /code/epolldir/Client1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/epolldir/Client1 -------------------------------------------------------------------------------- /code/epolldir/Sever: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/code/epolldir/Sever -------------------------------------------------------------------------------- /code/fork.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | int main(int argc,char** argv) 6 | { 7 | int fd; 8 | pid_t pid; 9 | pid=fork(); 10 | if(pid<0) 11 | { 12 | perror("fork"); 13 | } 14 | else if(pid>0) 15 | { 16 | wait(NULL); 17 | exit(EXIT_FAILURE); 18 | // 19 | } 20 | else 21 | { 22 | if(fd=open("/dev/tty1",O_RDWR)==-1) 23 | perror("open"); 24 | 25 | printf("pid=%d,ppid=%d\n",getpid(),getppid()); 26 | printf("sid=%d,tcgetsid=%d\n",getsid(getpid()),tcgetsid(fd)); 27 | printf("pigd=%d\n",getpgid(getpid())); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /docs/APUE环境搭建/image/1530766056596.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/docs/APUE环境搭建/image/1530766056596.png -------------------------------------------------------------------------------- /docs/APUE环境搭建/image/1530766270952.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/docs/APUE环境搭建/image/1530766270952.png -------------------------------------------------------------------------------- /docs/APUE环境搭建/image/1530766324344.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/docs/APUE环境搭建/image/1530766324344.png -------------------------------------------------------------------------------- /docs/APUE环境搭建/image/1530766411506.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/docs/APUE环境搭建/image/1530766411506.png -------------------------------------------------------------------------------- /docs/第10章-信号/第10章-信号.md: -------------------------------------------------------------------------------- 1 | # 第10章-信号 2 | 3 | -------------------------------------------------------------------------------- /docs/第11章-线程/第11章-线程.md: -------------------------------------------------------------------------------- 1 | # 第11章-线程 2 | 3 | -------------------------------------------------------------------------------- /docs/第12章-线程控制/第12章-线程控制.md: -------------------------------------------------------------------------------- 1 | # 第12章-线程控制 2 | 3 | -------------------------------------------------------------------------------- /docs/第13章-守护进程/第13章-守护进程.md: -------------------------------------------------------------------------------- 1 | # 第13章-守护进程 2 | 3 | -------------------------------------------------------------------------------- /docs/第14章-高级IO/第14章-高级IO.md: -------------------------------------------------------------------------------- 1 | # 第14章-高级IO 2 | 3 | -------------------------------------------------------------------------------- /docs/第15章-进程间通信/第15章-进程间通信.md: -------------------------------------------------------------------------------- 1 | # 第15章-进程间通信 2 | 3 | -------------------------------------------------------------------------------- /docs/第16章-网络IPC套接字/第16章-网络IPC套接字.md: -------------------------------------------------------------------------------- 1 | # 第16章-网络IPC套接字 2 | 3 | -------------------------------------------------------------------------------- /docs/第17章-高级进程间通信/第17章-高级进程间通信.md: -------------------------------------------------------------------------------- 1 | # 第17章-高级进程间通信 2 | 3 | -------------------------------------------------------------------------------- /docs/第18章-终端IO/第18章-终端IO.md: -------------------------------------------------------------------------------- 1 | # 第18章-终端IO 2 | 3 | -------------------------------------------------------------------------------- /docs/第19章-伪终端/第19章-伪终端.md: -------------------------------------------------------------------------------- 1 | # 第19章-伪终端 2 | 3 | -------------------------------------------------------------------------------- /docs/第1章-UNIX基础知识/第1章-UNIX基础知识.md: -------------------------------------------------------------------------------- 1 | # 第1章-UNIX基础知识 2 | 3 | -------------------------------------------------------------------------------- /docs/第20章-数据库函数/第20章-数据库函数.md: -------------------------------------------------------------------------------- 1 | # 第20章-数据库函数 2 | 3 | -------------------------------------------------------------------------------- /docs/第21章-与网络打印机通信/第21章-与网络打印机通信.md: -------------------------------------------------------------------------------- 1 | # 第21章-与网络打印机通信 2 | 3 | -------------------------------------------------------------------------------- /docs/第2章-UNIX标准及实现/第2章-UNIX标准及实现.md: -------------------------------------------------------------------------------- 1 | # 第2章-UNIX标准及实现 2 | 3 | -------------------------------------------------------------------------------- /docs/第3章-文件IO/第3章-文件IO.md: -------------------------------------------------------------------------------- 1 | # 第3章-文件IO 2 | 3 | -------------------------------------------------------------------------------- /docs/第4章-文件和目录/第4章-文件和目录.md: -------------------------------------------------------------------------------- 1 | # 第4章-文件和目录 2 | 3 | -------------------------------------------------------------------------------- /docs/第5章-标准IO库/第5章-标准IO库.md: -------------------------------------------------------------------------------- 1 | # 第5章-标准IO库 2 | 3 | -------------------------------------------------------------------------------- /docs/第6章-系统数据文件和信息/第6章-系统数据文件和信息.md: -------------------------------------------------------------------------------- 1 | # 第6章-系统数据文件和信息 2 | 3 | -------------------------------------------------------------------------------- /docs/第7章-进程环境/第7章-进程环境.md: -------------------------------------------------------------------------------- 1 | # 第7章-进程环境 2 | 3 | -------------------------------------------------------------------------------- /docs/第8章-进程控制/第8章-进程控制.md: -------------------------------------------------------------------------------- 1 | # 第8章-进程控制 2 | 3 | -------------------------------------------------------------------------------- /docs/第9章-进程关系/第9章-进程关系.md: -------------------------------------------------------------------------------- 1 | # 第9章-进程关系 2 | 3 | -------------------------------------------------------------------------------- /image/1533726645683.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yifengyou/learn-apue/703031243c4511868c7fd8f4eed560ba52dcab69/image/1533726645683.png --------------------------------------------------------------------------------