1.在nfs目录下创建 process.c文件
- #include<stdio.h>
- #include<fcntl.h>
- #include<stdlib.h>
- #include<unistd.h>
- #include<sys/types.h>
- #include<sys/wait.h>
- int main(int argc, char* argv[])
- {
- int stat;
- pid_t child;
- printf("/nTry to create new process./n");
- child = fork();
- switch(child)
- {
- case -1: //fault
- perror("fork./n");
- exit(EXIT_FAILURE);
- case 0: //child process
- printf("This is child./n");
- printf("/tchild pid is %d/n", getpid());
- printf("/tchild ppid is %d/n", getppid());
- exit(EXIT_SUCCESS);
- default: // father process
- waitpid(child,&stat, 0);
- printf("this is parent./n");
- printf("/tparent pid is %d/n", getpid());
- printf("/t parent ppid is %d/n", getppid());
- printf("/t child exited with %d/n", stat);
- exit(EXIT_SUCCESS);
- }
- return 0;
- }
2.创建makefile文件
- EXEC = process
- OBJS = process.o
- SRC = process.c
- CC = arm-linux-gcc
- CFLAGS = -o2 -Wall
- DFLAGS +=
- all:$(EXEC)
- $(EXEC):$(OBJS)
- $(CC) $(DFLAGS) -o $@ $^
- %.o:%.c
- $(CC) $(CFLAGS) -o $@ -c $<
- clean:
- @rm -vf $(EXEC) *.o *~
3.执行make,进行编译该文件。
- -bash-3.2# make
- arm-linux-gcc -o2 -Wall -o process.o -c process.c
- arm-linux-gcc -o process process.o
- -bash-3.2#
4.超级终端上,进行测试。
- /mnt/nfs/arm/project/test3 # ls
- makefile process process.c process.o
- /mnt/nfs/arm/project/test3 # ./process
- Try to create new process.
- This is child.
- child pid is 968
- child ppid is 967
- this is parent.
- parent pid is 967
- parent ppid is 924
- child exited with 0
- /mnt/nfs/arm/project/test3 #