今天瞎看 看到一本了解Unix进程 -- 理解UNIX进程 的书 不错,可以看看,使用的ruby语言,第一章讲的是一些基础的知识
1.输出进程号和父进程号:
puts Process.pid # 得到进程号
puts $$ # 同样得到进程号的方法
puts Process.ppid # 得到父进程号
2.在unix中一切都是文件,所以文件也是一种资源,有一个编号:
0-2代表的是标准输入,标准输出,标准错误.
puts STDIN.fileno
puts STDOUT.fileno
puts STDERR.fileno
3.所以,一个自己打开的文件,一般只能用3以上的数字了,如果关闭掉以后就可以再次使用了:
passwd = File.open('./pid.rb')
puts passwd.fileno hosts = File.open('./how_as_fileno.rb')
puts hosts.fileno # Close the open passwd file. The frees up its file descriptor
# number to be used by the next opened resource. passwd.close
null = File.open('./pid.rb')
puts null.fileno
4. 打开一个文件,查看他的编号,一般会是3:
passwd = File.open("./pid.rb")
puts passwd.fileno