[Date Prev][Date Next][Date Index]
[ece333] -- Preparation for Lab assignment #3
Class,
Tommorrow, I will be going over Lab #3. I will assume that you know C(or C++) (especially working with pointers).
Here are some links that i had collected when I was doing CS485, which might prove useful for creating Makefiles, using gdb etc.
http://mia.ece.uic.edu/~papers/cs485/index.html
Two important C/C++ functions that you will use in this lab are:
fork and pipe;
So make your self comfortable with these two functions. Here is a test code, which you can compile using
"gcc -o test test.c" command.
----------------------------------------------
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(void){
int fd[2];
int pid;
if (pipe(fd) < 0) printf("Error pipe\n");
if ((pid = fork())< 0) printf("Error fork\n");
if (pid == 0){
//child close(0);
dup(fd[0]);
close(fd[0]);
close(fd[1]);
if (execlp("/usr/bin/wc", "/usr/bin/wc", NULL) < 0)
printf("Error exe cjoild\n");
}else{
//Parent close(1);
dup(fd[1]);
close(fd[0]);
close(fd[1]);
if (execl ("/usr/bin/ls", "/usr/bin/ls", NULL) < 0)
printf("Error exe parent\n");
}
}
Comments and corrections are appreciated and can be sent to
papers@mia.ece.uic.edu.
Click here for ©opyright information.