diff --git a/newlib/examples/Makefile b/newlib/examples/Makefile index a18d6b33..6eaa1af8 100644 --- a/newlib/examples/Makefile +++ b/newlib/examples/Makefile @@ -2,27 +2,28 @@ ARCH = x86 NEWLIB = ../x86/i586-metalsvm-elf32 MAKE = make CC = gcc -CFLAGS = -m32 -O2 -nostdinc -Wall -fno-builtin -I$(NEWLIB)/include -I../../include -I../../arch/$(ARCH)/include #-fno-stack-protector +CFLAGS = -m32 -O2 -nostdinc -Wall -fno-builtin -I$(NEWLIB)/include -I../../include -I../../arch/$(ARCH)/include -fno-stack-protector LDFLAGS = -m32 -nostdlib -L$(NEWLIB)/lib # other implicit rules %.o : %.c $(CC) -c $(CFLAGS) -o $@ $< -default: - $(MAKE) hello +default: all -all: - $(MAKE) hello +all: hello test_fork + +test_fork: test_fork.o + $(CC) -T link.ld -o $@ $(LDFLAGS) $< hello: hello.o $(CC) -T link.ld -o $@ $(LDFLAGS) $< clean: - $(RM) *.o *~ + $(RM) hello test_fork *.o *~ depend: - $(CC) -MM $(CFLAGS) hello.c > Makefile.dep + $(CC) -MM $(CFLAGS) *.c > Makefile.dep -include Makefile.dep # DO NOT DELETE diff --git a/newlib/examples/test_fork.c b/newlib/examples/test_fork.c new file mode 100644 index 00000000..f28839f1 --- /dev/null +++ b/newlib/examples/test_fork.c @@ -0,0 +1,38 @@ +/* + * Copyright 2010 Stefan Lankes, Chair for Operating Systems, + * RWTH Aachen University + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of MetalSVM. + */ + +#include +#include +#include +#include +#include +#undef errno +extern int errno; + +int main(int argc, char** argv) +{ + pid_t pid = fork(); + + if (pid == 0) // child + printf("Hello from child process!\n"); + else + printf("Hello from parent process! pid = %u\n", pid); + + return errno; +}