mirror of
https://github.com/gatieme/LDD-LinuxDeviceDrivers.git
synced 2026-09-22 20:53:34 +08:00
description: scheduler and memory
This commit is contained in:
Executable
BIN
Binary file not shown.
@@ -0,0 +1,37 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MAP_SIZE 1024*1024
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
unsigned char *m;
|
||||
int i;
|
||||
pid_t pid;
|
||||
|
||||
m = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
|
||||
for (i = 0; i < MAP_SIZE; i++)
|
||||
m[i] = 10;
|
||||
|
||||
pid = fork();
|
||||
if (pid == -1) {
|
||||
exit(1);
|
||||
} else if (pid == 0) {
|
||||
sleep(10);
|
||||
} else {
|
||||
sleep (5);
|
||||
|
||||
/* Cow */
|
||||
for (i = 0; i < MAP_SIZE; i++)
|
||||
m[i] = 20;
|
||||
printf("cow is done in parent pscess\n");
|
||||
sleep(10);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
target=fork COW
|
||||
|
||||
|
||||
|
||||
all:$(target)
|
||||
|
||||
fork : fork.o
|
||||
$(CC) $^ -o $@ $(LDFLAGS)
|
||||
|
||||
COW : COW.o
|
||||
$(CC) $^ -o $@ $(LDFLAGS)
|
||||
|
||||
%.o : %.c
|
||||
$(CC) -g -c $^ -o $@ $(CFLAGS) $(DEFINES)
|
||||
|
||||
clean :
|
||||
rm -rf *.o
|
||||
rm -rf $(target)
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,26 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
|
||||
int data = 10;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int pid;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
printf("Child process %d, data %d\n", getpid(), data);
|
||||
data = 20;
|
||||
printf("Child process %d, data %d\n", getpid(), data);
|
||||
} else {
|
||||
sleep(1);
|
||||
printf("Parent process %d, data %d\n", getpid(), data);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user