Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1000608
  • 博文数量: 361
  • 博客积分: 25
  • 博客等级: 民兵
  • 技术积分: 1759
  • 用 户 组: 普通用户
  • 注册时间: 2012-09-22 23:18
个人简介

学海无涯 个人blog lnmps.com 新站

文章分类

全部博文(361)

文章存档

2017年(1)

2015年(2)

2014年(55)

2013年(303)

分类: LINUX

2013-04-13 19:28:55

以下几个创建子进程的情况。(以下英文摘自info bash)

1&,提交后台作业

If a command is terminated by the control operator `&', the shell executes the command asynchronously in a subshell.

2:管道

Each command in a pipeline is executed in its own subshell

3:括号命令列表

()操作符

     Placing a list of commands between parentheses causes a subshell

     environment to be created

4:执行外部脚本、程序:

When Bash finds such a file while searching the `$PATH' for a command, it spawns a subshell to execute it.  In other words, executing

                     filename ARGUMENTS

        is equivalent to executing

                   bash filename ARGUMENTS

 

说明:大致上子进程的创建包括以上四种情况了。需要说明的是只要是符合上边四种情况之一,便会创建(fork)子进程,不因是否是函数,命令,或程序,也不会因为是内置函数(buitin)或是外部程序。


此外,上边提到子进程创建与执行的二个步骤,shell子进程的创建在步骤之一并无多大差别,一般还是父进程调用fork产生进程环境,估在第二步exec的时候,是存在差别的。


shell做为解释语言程序,提供给第二步exec加载和执行的程序体并不是脚本本身,而是由第一行#!指定的,默认为shell程序,当然也可以是awk,sed等程序.


shell同时提供二种不创建子程序的进程创建方式

                         1source命令,使用方法

Source   filename ARGUMENTS

 filename ARGUMENTS

 此种方法,直接在当前shell进程中执行filename脚本,filename结束后继续返回当前shell进程

2exec命令,使用方法

Exec  filename ARGUMENTS

此种方法直接在当前shell进程中执行filname脚本,filename结束后退出当前shell进程

阅读(3311) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~