[cs631apue] Several Questions

Jan Schaumann jschauma at stevens.edu
Thu Sep 15 22:38:01 EDT 2016


kthompso <kthompso at stevens.edu> wrote:
> On 09/15/2016 5:12 PM, bzhang41 wrote:
 
> > 3. How can I run the I/O efficiency example in the slides ?
> > I can not "make tempfiles" shows in the slides. Can Prof. send us the
> > makefile ? so we can try the example.
> 
> I think the shell commands being shown after the "make" commands
> are actually just copied out of their respective make sections.

Correct.  The Makefile itself is not needed -- I just use it to save me
the typing in class.

> Basically you should have everything you need to run that example right
> there.  Just combine all those commands into a shell script, minus the
> make commands (or you could do a makefile... seems like an odd use of
> make to me though).

Not quite so odd.  make(1), as we will see later on in the semester, can
be used for a variety of things.  It's primary use is to execute
commands with dependencies on files.  In this case, I use it to let me
run one command to execute the example as well as to prepare the files
needed, but only do the latter part if necessary.

We'll discuss the use of make(1) later in the semester, but for now you
can remember that it can be a convenient way of saving yourself some
typing while at the same time avoiding unnecessary command execution.

> > Actually, I also don?t understand
> > what does "dd if=/dev/urandom of=tmp/file$n count=204800" mean ? I
> > know the purpose is creating several files. I don?t understand the
> > grammar here.
> > Is there any material I can catch up to understand this grammar ?
> 
> Read the man pages.

Sound advice, and always a good start.

> > Finally, `stat -f "%k" tmp/file1 # stat -c "%o" tmp/file1`,  I checked
> > the stat in man, but I didn?t find %k option, and I also don?t
> > understand what the symbol `#` does here ?
> 
> This one is confusing.

It is.  The issue is that different versions of Unix sometimes use
different commands or different command syntax to accomplish the same
thing.  We will see this every now and then.

On Linux, the stat(1) command takes the "-c" flag with the "%o" argument
to get the optimal file I/O size (i.e. the file system's block size).
On BSD derived systems, such as Mac OS X (where much of the userland
actually comes from NetBSD), the stat(1) command uses '-f "%k"'
instead.

To illustrate this discrepancy, I included both commands.  The '#' is
just a shell comment character: if you were to copy the whole line and
pasted it into a shell, it would only execute the first command.

-Jan


More information about the cs631apue mailing list