From: SMTP%"lchen@nimbus.ocis.temple.edu" 24-OCT-1996 12:36:16.48
To: ingargiola@falcon.cis.temple.edu
CC:
Subj: Report
On Tuesday, I covered linking programs, using make, and the debugger: gdb .
These are examples:
makefile:
program: foo.o bar.o
cc -o program foo.o bar.o
foo.o: foo.c
cc -c foo.c
bar.o: bar.c
cc -c bar.c
gdb:
gcc -g foo.c // compiling
gdb foo.out // debugging
list // listing
break line_number // break point
break +offset
run
p 'foo' // check a variable
Some examples about fork(), pipe(), signals.
fork():
#include
#include
int glob 6;
main()
{
pid_t pid;
if ((pid=fork())<0)
printf("Fork error!");
else
if (pid==0)
{ glob++;
printf("This is child, glob here is:%d\n", pid);
}
else printf("This is parent, glob here is:%d\n", pid);
exit(0);
}
pipe:
#include
#include
main()
{
pid_t pid;
int fd[2];
char buf1[20], buf2[20];
pipe(fd);
if(( pid=fork())==-1)
printf("Fork error!\n");
else
{
if (pid==0)
{ sprintf(buf1, "Child writes it.\n");
write(fd[1], buf1, 20);
exit(0);
}
else {
wait(0);
read(fd[0], buf2, 20);
printf("%s", buf2);
}
}
}
Using signals:
kill(pid_t pid, int signo); // sending a signal
example:
kill(pid[1], SIGUSR1);
void (*signal (int signo, void (*func) (int))) (int);
example:
signal(SIGUSR1, display);
The handler:
void display(int signo)
{
printf( // The statistc data//);
}