bash
and other popular shells.
Copy the hw4 template to your turn-in directory thus:
svn cp svn://bits.cs.uic.edu/cs385s11/notes/homeworks/hw4 .
ls
do the same thing as /bin/ls
, but also make sure that mydir/mybinary
still works correctly.
HINT: getenv()
to get the environment variable, then strsep()
to split it into multiple path strings. Finally, sprintf()
to compose a full path out of its components.
echo hello world
, should produce hello world
.
HINT: you could use strsep()
to split the arguments into an array, which you then pass to execve()
.
ls > /tmp/templ
should create a file (with correct permissions) containing the output of ls. Similarly wc < /tmp/templ
should use the file as input, and wc < /tmp/templ > /tmp/count
uses both input and output redirection.
HINT: use open()
to open a file, and dup2()
to change where stdin(0) or stdout(1) points to.
ls -l | sort -n -k 5 | cut -c 27-34 > /tmp/sizes
produces a file containing a sorted list of file sizes.
HINT: this is by far the most challenging part of the homework. Use fork()
as in the template code to start up multiple concurrent processes, pipe()
to create pipes through which processes communicate, and dup2()
to redirect output into and out of pipes. Finally, use waitpid()
to wait for child processes to finish.
./echo.hw4 hello world hello world helloReplace any occurrence of $1,$2,$3 etc with the first, second, third command line argument respectively. HINT: this one will require some manual string manipulation, but
strchr()
to find each "$", and strncpy()
to copy part or all of strings is a good start. Copyright 2016 The Board of Trustees of the University of Illinois.webmaster@cs.uic.edu |
WISEST Helping Women Faculty Advance Funded by NSF | ![]() | ![]() |