<!doctype
html public "-//w3c//dtd html 4.0 transitional//en">
CS 476/576
Systems Programming
Fall 2011
Midterm Exam
Time 2 & 1/2 hours
Open Book & Notes
Login:
Name:
Question 1: 25 points
The following commands lists the information about faculty group:
% ypcat group | egrep
"^faculty:"
faculty:*:13:ajay,ibl,gpd,jrcrouch,grosch,mukka,olariu,cmo,pothen,price,toida,wilson,zeil,zubair,mln,brunelle,maly,rgupta,dkaneko,webgrade
What is the output of the next shell script?
#!/bin/sh
ypcat
group | egrep “^faculty:” | tr ":" "\n" | tail -1 | tr
"," "\n"
As you can see there are some faculty members who are not listed in the
output of above script, e.g. wahab.
Write a script called missingfaculty that lists all those faculty that are missing
from the output of the above script.
For example, my implementation produces:
bsympson
cboyle
chengapp
dranjan
jdm
jhe
kjohnso
kmaly
mweigle
nadeem
nikos
sji
taustin
wahab
yaohang
Question 2: 25 points
The command who shows an
entry for each login at the current
host.
Write a program called whoname
to list the full name of each login.
Here is an example:
% hostname
vega
% who
ibl pts/2 2011-09-19 11:32 (ip24-254-195-222:S.3)
ibl pts/3 2011-09-19 11:32 (ip24-254-195-222:S.4)
ibl pts/4 2011-09-19 11:32 (ip24-254-195-222:S.5)
ibl pts/5 2011-09-19 11:32 (ip24-254-195-222:S.6)
ibl pts/6 2011-09-19 11:32 (ip24-254-195-222:S.7)
ibl pts/7 2011-09-19 11:32 (ip24-254-195-222:S.0)
ibl pts/13 2011-09-19 13:10 (dhcp-132.cs.odu.edu)
cs476 pts/14 2011-10-21 17:54 (dhcp-154.cs.odu.edu)
ibl pts/12 2011-09-25 12:39 (ip24-254-195-222:S.8)
ibl pts/15 2011-09-19 11:32 (ip24-254-195-222:S.1)
kpadia pts/17 2011-10-23 19:12 (dhcp-72.cs.odu.edu)
pchodibo pts/18 2011-10-23 19:30
(wsip-98-190-61-27.hr.hr.cox.net)
ibl pts/19 2011-09-19 11:32 (ip24-254-195-222:S.2)
zeil pts/22 2011-10-02 15:27 (:1111.0)
mln pts/9 2011-09-29 14:30 (dhcp-24.cs.odu.edu)
cs476 pts/29 2011-10-21 21:24 (dhcp-154.cs.odu.edu)
cs476 pts/31 2011-10-21 19:03 (dhcp-154.cs.odu.edu)
khaled pts/32 2011-10-23 17:51 (dhcp-152.cs.odu.edu)
tlavang pts/34 2011-10-23 21:42 (tejaswini-pc.odu.edu)
% whoname
cs476 grader
Dr. Irwin Levinstein
Khaled Almahallawy
kalpesh padia
Michael Nelson
pavan chodiboina
tejaswini lavang
Steven J. Zeil
%
Question 3: 10 points
Write a curses program called decorate.c to
use “*” to frame the tty as
shown.
Assume the tty has 20
rows and 80 columns.

Question 4: 20 points
Modify
the largecircle.c program (partially listed below, use the
provided spaces to write the missing code)
to draw the largest possible
circle centered at the click point inside the drawing area.
For
example; here is a snapshot of my implementation:

main(argc,argv)
int argc;
char **argv;
{
Display
*display;
Window root,
window;
long
fgcolor, bgcolor;
int screen,
pointx, pointy ;
long
eventmask = ButtonPressMask|ExposureMask|KeyPressMask;
XEvent
event;
XGCValues
gcval;
GC draw;
Colormap
cmap;
XColor
color, ignore;
char
*colorname = "Red";
display =
XOpenDisplay(argv[1]);
root =
RootWindow(display,screen = DefaultScreen(display));
fgcolor =
BlackPixel(display,screen);
bgcolor =
WhitePixel(display,screen);
window =
XCreateSimpleWindow(display,root,0,0,800,800,2,fgcolor,bgcolor);
cmap =
DefaultColormap (display, screen);
XAllocNamedColor(display, cmap, colorname, &color, &ignore);
fgcolor =
color.pixel;
gcval.foreground = fgcolor;
gcval.background = bgcolor;
draw =
XCreateGC(display,window,GCForeground|GCBackground,&gcval);
XSelectInput(display,window,eventmask);
XMapWindow(display,window);
for (;;) {
XWindowEvent(display,window,eventmask,&event);
switch
(event.type) {
case Expose:
XClearWindow(display,window);
break;
case ButtonPress:
pointx = event.xbutton.x;
pointy = event.xbutton.y;
XDrawPoint (display,window,draw, pointx, pointy);
break;
case
KeyPress:
exit(0);
}
}
}
Question 5: 20 points
The following program xmbuttons (partially
listed below, use the provide spaces to write your code) creates a
motif interface with a single button (Quit button).
Modify the program to add 3 more buttons
labeled:
missingfaculty
whoname
decorate
to execute these commands.
We
would like each command displays its output inside its own xterm window.
To execute a command inside an xterm, we use:
% xterm –e command
For example:
% xterm –e ls –lt
creates an xterm, display the output of ls
–lt, and then the xterm disappears.
To force the
xterm to stay t for 60 seconds
before it disappears, we will use the
following program called xcmd.
The xcmd
program executes the command, sleep 60 seconds and then exits.
main (int argc, char *argv[])
{
char cmd[100];
int i;
for (i=1; i< argc; i++) {
strcat(cmd, argv[i]);
strcat(cmd, " ");
}
system(cmd);
sleep(10);
}
For example, we can use this program as follows:
% xterm –e xcmd ls –lt &
use
this xcmd to invoke the three
programs in the xmbuttons.
void quitCallback ( Widget
w, XtPointer clientData, XtPointer callData );
void main ( int argc, char
**argv )
{
Widget shell, commands, quit;
XtAppContext app;
shell=XtAppInitialize(&app,"Xecute",NULL,0,&argc,argv,NULL,NULL,0);
commands=XtVaCreateManagedWidget("commands",xmRowColumnWidgetClass,shell,
XmNnumColumns, 3, XmNorientation,
XmHORIZONTAL, NULL );
quit=XtVaCreateManagedWidget("Quit",xmPushButtonWidgetClass,commands,NULL,0);
XtAddCallback ( quit, XmNactivateCallback,
quitCallback, NULL);
XtRealizeWidget ( shell );
XtAppMainLoop ( app );
}
void quitCallback ( Widget
w, XtPointer clientData, XtPointer callData )
{
exit ( 0 );
}