Chinaunix首页 | 论坛 | 博客
  • 博客访问: 150694
  • 博文数量: 25
  • 博客积分: 1632
  • 博客等级: 上尉
  • 技术积分: 324
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-02 21:19
文章分类

全部博文(25)

文章存档

2011年(13)

2010年(12)

我的朋友

分类:

2010-04-11 20:31:22

我们现在是在有最小系统的板子上进行"hello"程序的实现,用来验证最小系统是不是工作正常,
首先我们进入文件系统目录,进行下面的操作:
# mkdir app
# cd app/
# mkdir hello
# cd hello
# vim hello.c
#include
#include
#include
#include
int main ( void )
{
    pid_t result;
    result = fork ( );
    if ( result == -1 )
         {
           perror ("fork");
           exit;
         }
    else if ( result == 0 )
         printf ("Then return value is %d\n in child process!!\n My pid is %d\n",result,getpid ( ) );
    else
         printf ("Then return value is %d\n in father process!!\n My pid is %d\n",result,getpid ( ) );
    printf ("hello!\n");
    return 0;
}
保存退出:
# arm-none-linux-gnueabi-gcc -static hello.c -o hello
# ls
hello  hello.c
现在就生成可执行文件"hello"
然后从新生成cramfs文件系统,下载到板子上去运行(因为我的板子没网卡,故不能实现NFS文件系统来进行开发调试),重起开发板,可以看到下面的信息
***********************************************
             Start ARM.....                   
             2010 04 11                       
             microcreat                       
***********************************************
starting pid 739, tty '': '-/bin/sh'
***************Start /etc/profile************************
***************/etc/profile is done**********************
[root@microcreat /]$ls
app      dev      home     mnt      sbin     usr
bin      driver   lib      proc     sys      var
boot     etc      linuxrc  root     tmp
[root@microcreat /]$cd app/
[root@microcreat /app]$ls
hello    ledtest
[root@microcreat /app]$cd hello/
[root@microcreat hello]$pwd
/app/hello
然后我们在板子上运行"hello"
[root@microcreat hello]$./hello
Then return value is 0
 in child process!!
 My pid is 743
hello!
Then return value is 743
 in father process!!
 My pid is 742
hello!
[root@microcreat hello]$                                            
可以看到运行正常.
需要注意的地方就是编译的时候需要用静态编译的方式,因为我们制作根文件系统是采用静态的方式进行制作的.                 
阅读(801) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~