您的位置:首页 > 运维架构 > Shell

对shell的理解

2014-06-10 11:09 113 查看
一直对shell的认识模棱两可,仔细查看了下linux下进程,有了近一步的理解。

UID PID PPID C STIME TTY TIME CMD

root 1 0 0 Apr23 ? 00:00:00 init [5]

root 2780 1 0 Apr23 ? 00:00:00 /usr/sbin/sshd

root 8203 2780 0 10:10 ? 00:00:00 sshd: user [priv]

user 8207 8203 0 10:10 ? 00:00:00 sshd: user@pts/1

user 8208 8207 0 10:10 pts/1 00:00:00 -bash

user 8321 8208 0 10:38 pts/1 00:00:00 ./a.out

user 8322 8208 0 10:38 pts/1 00:00:00 ps -ef



用户进程产生过程:

1.Linux系统启动时,0进程天然产生;

2.0进程会fork一个1号进程(0进程只有一个子进程,就是1号进程;1号进程是所有进程的模板,其它进程要么是1号进程的子进程,要么是孙进程);

3.1号进程会创建一个sshd(OpenSSH Secure ShellDaemon)进程;顾名思义,shhd就是为ssh登录提供服务的,当shhd挂了,用户sshd肯定无法登录。(sshd
is a process belonging to the OpenSSHSecure Shell Daemon which offers a encrypted and secure shell across theInternet.)

4.当用户ssh登录时, sshd会创建它的子进程sshd: user[priv];

5.sshd: user [priv]会创建一个sshd: user@pts/1,转入用户进程;

6.user@pts/1会创建子进程bash;

7.Bash是一切用户进程的父进程,当我们在TTY(teletype,通常使用tty来简称各种类型的终端设备)下运行命令、程序,bash都会fork一个新进程.



我们常说shell是linux内核与用户之间的“接口”,当我们使用bash时,bash就是内核与用户之间的“接口”。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: