CMPS-3600 - Fall 2024 - Semester Project
Phase-1 - Signals and execve
----------------------------
Start with a working version of your
phase1.c program.
Copy the program to
3600/8/myphase1.c
Do this work in your
3600/8 folder.
Functionality for phase-1
-------------------------
1. Start your parent window.
2. In the parent, press 'C' key to create a child window.
3. In the parent:
press 'X' to change the color of the child window
press 'E' to see the xeyes window
press 'K' to see the xclock with a second-hand
4. Use execve function to start xeyes and xclock.
5. The parent window will use a signal handler to know when its
child windows have closed.
6. Keep the window text updated.
Notice when child windows are active, the parent text changes.
Discussion...
Start xeyes and xclock as child processes. If those processes end by themselves,
they will send a SIGCHLD to the parent process. Use a signal handler to trap
those signals.
Even if the parent terminates the child windows, the child will still send
a SIGCHLD to the parent.
If a SIGCHLD is received, use the following function call to see which
child process sent the signal. Do this inside the parent's signal handler.
int status;
int child_pid = waitpid(-1, &status, WUNTRACED | WNOHANG);
No calls to system() function are allowed
call execve() instead.
system-vs-execve
Code samples
------------
To draw some text on the screen
-------------------------------
Define this function...
void drawString(int left, int top, char *str)
{
XDrawString(g.dpy, g.win, g.gc, left, top, str, strlen(str));
}
Call it like this...
drawString(10, 20, "Parent window");
To use a bold font for easier reading
-------------------------------------
Call this function at top of render():
XSetFont(g.dpy, g.gc, XLoadFont(g.dpy, "9x15bold"));
Fonts to choose from:
"fixed", "5x8", "6x9", "6x10", "6x12", "6x13", "6x13bold",
"7x13", "7x13bold", "7x14", "8x13", "8x13bold", "8x16", "9x15",
"9x15bold", "10x20", "12x24"
Some are bigger, some are more bold.
Easy reading.
Phase-2 - Drag-n-drop from parent to child - pipes
--------------------------------------------------
Start with your
myphase1.c program.
Copy the program to
3600/c/myphase2.c
Do this work in your
3600/c folder.
You may get the dnd.c program from class here:
/home/fac/gordon/public_html/3600/examples/d/dnd.c
Functionality for phase-2
-------------------------
1. Start your parent window.
2. In the parent, press 'C' key to create a child window.
3. Draw a rectangle in the parent window.
press 'R' or just have the rectangle already there (somewhere).
4. When the box dragging starts, show a confirmation message in the child.
5. If dragging stops, child will remove its confirmation message.
6. When drop is complete, the parent box fragments will be gone.
The child will own the box.
7.
No calls to system() function are allowed
call execve() instead.
system-vs-execve
8. Requirement
Every time you press 'R' to create a rectangle, it should have a somewhat
random shape and color. Do it something like this...
box.width = rand() % 20 + 40;
box.height = rand() % 20 + 40;
box.color = rand();
The test will go in this order...
1. start parent window
2. create a child window
3. generate random box
4. drag box to child
Here is the program sequence visually ...
Program starts and parent spawns child
A box appears
The box is being dragged by the parent
Box has been dragged to child
Discussion...
You may leave all of phase-1 functionality in your phase-2 program.
The child window will "listen" for messages inside a thread loop.
The parent will also "listen" for messages inside a thread loop.
For two-way communication, choose one of these...
• Two pipes
• One pipe and a message queue
• One pipe and a shared memory segment
Diagram of pipe 2-way communication
Hints...
The parent will open the pipes or create a message queue.
The parent will tell the child about pipes, etc. on the execve command-line.