csh
, awk
, and perl
.
The interface to the operating system
is easily accessed with the "C" language. The operating system
calls look like "C" function calls. The system calls
are documented in section 2 of the manual pages. Library calls
are documented in section 3 of the manual pages.
This lab will also be used to look at the effects of umask
on protection bits when a file is created.
hello.c
with the
following "C" program:
/* Program to print "hello, world" */ /* Kernighan & Richie "The C Programming Language" */ /* Copyright 1978 page 6 */ #include <stdio.h> main() { printf("hello, world\n"); }
(cc is the standard C Compiler)gort:~>
cc hello.c
or
(gcc is the gnu C Compiler)
gort:~>
gcc hello.c
The standard output of the compiler is a.out. You can use
the option -o
to put the executable in another file.
-rwxrwxrwx 1 ltaber 15165 Oct 13 14:30 a.out
gort:~>
ls -l a.out
gort:~>
a.out
(run the program)
hello, world (resulting output)
umask
on
file protection bits during file creation.
You may have noted above that the protection bits that you saw
on your a.out
file did not match my example. This is
because you may have a different umask
setting. To
look at your current setting try:
Your output should be an octal number that is the current setting forgort:~>
umask
umask
. If a bit is set in your umask
it will prevent
that bit from being set when a file is created. Set your umask
to zero.
Recompile your program and look at the protection bits. It should now match my example. Now try a more restrictive setting:gort:~>
umask 0
Recompile your program and look at the protection bits forgort:~>
umask 077
a.out
again. This will only allow you to read, write, or execute
the program. Your results should look like this:
Try a-rwx------ 1 ltaber 15165 Oct 13 14:30 a.out
gort:~>
ls -l a.out
umask
setting of 0777. Write on your lab what happens and
explain why.
args.c
with the following C program:
/* Program to print arguments to a program */ /* L Taber October 13, 1992 PCC */ #include <stdio.h> main(argc, argv ) int argc; char * argv[ ]; { int i; printf("argc = %d File name = %s\n", argc, argv[0]); for ( i=1; i<argc; i++) printf(" arg[%d] = %s\n" ,i,argv[i]); printf("\n"); }
Compile and test the program.
test1
":
#!/bin/sh # # L Taber Argument passing # test script a.out $@ a.out $* a.out "$@" a.out "$*" a.out '$@' a.out '$*'
The output should look as follows:gort:~>
test1 "A B" 'c d' e
argc = 6 File name = a.out arg[1] = A arg[2] = B arg[3] = c arg[4] = d arg[5] = e argc = 6 File name = a.out arg[1] = A arg[2] = B arg[3] = c arg[4] = d arg[5] = e argc = 4 File name = a.out arg[1] = A B arg[2] = c d arg[3] = e argc = 2 File name = a.out arg[1] = A B c d e argc = 2 File name = a.out arg[1] = $@ argc = 2 File name = a.out arg[1] = $*
Place the lab in the instructor hand-in box in BUS R6E, the "terminal room".your name TABER CSC137 Lab 4.10: C Programming and the results of aumask
of zero