Browse Source

Simple test programs to fork and scanf

rafael 9 years ago
parent
commit
d180b264d1
3 changed files with 48 additions and 0 deletions
  1. 17 0
      BUILD.conf
  2. 11 0
      sys/src/test/saymyname/say.c
  3. 20 0
      sys/src/test/to_fork/to_fork.c

+ 17 - 0
BUILD.conf

@@ -67,6 +67,23 @@ test_hello()
 	LDFLAGS_EXTRA="-static -e_main"
 }
 
+test_to_fork()
+{
+	BUILD_IN="to_fork.c"
+	BUILD_OUT="to_fork"
+	CLEAN_COM="rm -f *.o"
+	LIBS_TO_LINK="stdio c"
+	LDFLAGS_EXTRA="-static -e_main"
+}
+
+test_saymyname()
+{
+	BUILD_IN="say.c"
+	BUILD_OUT="say"
+	CLEAN_COM="rm -f *.o"
+	LIBS_TO_LINK="stdio c"
+	LDFLAGS_EXTRA="-static -e_main"
+}
 cmd_cp()
 {
 	BUILD_IN="cp.c"

+ 11 - 0
sys/src/test/saymyname/say.c

@@ -0,0 +1,11 @@
+#include <u.h>
+#include <libc.h>
+#include <stdio.h>
+
+void main()
+{
+	char nombre[25];
+	printf("Your name?: ");
+	scanf("%s", &nombre);
+	printf("\n\nHello %s\n",nombre);
+}

+ 20 - 0
sys/src/test/to_fork/to_fork.c

@@ -0,0 +1,20 @@
+#include <u.h>
+#include <libc.h>
+#include <stdio.h>
+
+void main()
+{
+	int pid = fork();
+	if (pid == 0)
+	{
+		printf("I'm the father\n");
+	}
+	else if (pid > 0)
+	{
+		printf("I'm the child\n");
+	}
+	else
+	{
+		printf("fork() error\n");
+	}
+}