add example program to fork a process

This commit is contained in:
Stefan Lankes 2011-02-16 14:46:39 +01:00
parent 6bb932acf9
commit 77f73a1499
2 changed files with 46 additions and 7 deletions

View file

@ -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

View file

@ -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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#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;
}