📄 unix编程应用问答scz.html
字号:
1.2 如何增加交换空间
A: WT <wt@server.domain.top>
你无法改变分区大小,但是可以增加/删除交换文件,效果类似交换分区。下列命令
在根目录下创建一个500MB的交换文件,名为swapfile
# mkfile 500m /swapfile
下列命令将使之生效
# swap -a /swapfile
现在你有了额外的500MB交换空间,为了每次重启后依旧有效,编辑/etc/vfstab文件
增加如下行
/swapfile - - swap - no -
# swap -l
这里"-l"意味着"list",显示所有交换空间。仔细阅读"swap"和"mkfile"的手册页。
1.3 为什么我不能在/home目录下创建子目录
Q: Solaris 7下,root身份,当我试图在/home目录下创建子目录时,系统拒绝,为
什么?
A: mohansundarraj
如果/etc/rc2.d/S74autofs脚本中automount(1M)守护进程已经mount了/home,就是
这种现象,而这还是缺省安装后的情形。可以
# /etc/init.d/autofs stop
# umount /home
然后你就可以用root身份在/home下创建子目录,增加文件了。为了永久取消autofs
特性,可以将/etc/rc2.d/S74autofs脚本改名,并注释掉/etc/auto_home、
/etc/auto_master两个文件中的入口点。
SPARC/Solaris的缺省用户主目录是/export/home,而不是/home。
1.4 如何改变一台主机的locale
Q: 一台SPARC/Solaris 8运行在US locale环境中,现在我们想让它运行在
IE(Ireland) locale环境中,以便可以使用欧洲日期格式,怎么办?
A: Sharad Ramachandran <estancio@hotmail.com>
运行sys-unconfig,在此之前请man -s 1M sys-unconfig,:-)
A: chad schrock <chad@radix.net>
天啊,为了拍死一只苍蝇,你要引爆原子弹吗?
只需要做如下操作,在你的.cshrc/.profile/.bashrc等启动脚本中设置$LANG环境变
量的值为en_UK,注销,重新登录即可。为了使这个设置全局有效,修改
/etc/default/init文件,LANG=en_UK,重启动。
--------------------------------------------------------------------------
# @(#)init.dfl 1.2 92/11/26
#
# This file is /etc/default/init. /etc/TIMEZONE is a symlink to this file.
# This file looks like a shell script, but it is not. To maintain
# compatibility with old versions of /etc/TIMEZONE, some shell constructs
# (i.e., export commands) are allowed in this file, but are ignored.
#
# Lines of this file should be of the form VAR=value, where VAR is one of
# TZ, LANG, or any of the LC_* environment variables.
#
TZ=GMT+8
LANG=zh.GBK
--------------------------------------------------------------------------
参看locale(1)和locale(5),了解更多关于locale的信息。运行"locale -a",查看
当前系统所支持的所有locale。
A: Sun Microsystems 2001-06-12
有三种方式改变locale。首先用"locale -a"命令确认系统中已安装的locale
1) 从CDE登录屏幕上修改locale
选择 options -> languages -> choose the new locale
注意,如果登录用户的初始化文件中有不同的locale设置,将优先于系统全局locale
设置。
2) 临时设置locale(shell相关的)
ksh : LANG=<locale>
sh : LANG=<locale>
export LANG
csh : setenv LANG <locale>
bash: export LANG=en_US(zh.GBK)
3) vi /etc/default/init
增加如下内容
LANG=<locale>
LC_ALL=<locale>
重启系统。
运行"locale"命令确认改变生效。
如果你希望使用的locale并未安装,参看如下文档安装locale
Solaris 8 : <<International Language Environments Guide>>
Solaris 7 : <<Solaris Internationalization Guide For Developers>>
Solaris 2.6: <<Solaris Internationalization Guide for Developers>>
D: scz <scz@nsfocus.com> 1998-08
SPARC/Solaris 2.5下,为了在vi中正确看到中文需要设置环境变量
sh
LANG=C;export LANG
LC_CTYPE=iso_8859_1;export LC_CTYPE
csh
setenv LANG zh
关于设置LANG这个环境变量涉及到/usr/lib/locale下的目录权限。
1.5 Solaris 7自动注销
Q: 怎样设置才能30秒后自动注销
A: shridhara
不幸的是,Solaris对此没有什么好的支持。如果正在使用telnet会话,或许可以考
虑"logout"变量,参看telnet的手册页。一个变通的办法,使用K-Shell,它支持
TMOUT变量,用于指定非活动时限(以秒为单位)。比如,如果一个shell会话3分钟内
不活动,则终止这个shell会话
$ TMOUT=180;export TMOUT
可以在用户的.profile文件中放置该行。缺点是你只能使用ksh。
D: scz <scz@nsfocus.com>
vi /etc/default/login
# TIMEOUT sets the number of seconds (between 0 and 900) to wait before
# abandoning a login session.
#
TIMEOUT=180
这里的超时设置针对登录过程,而不是登录成功后的shell会话超时设置。
1.6 一个目录拥有setgid设置,怎么理解
Q: 对一个目录做了setgid设置,可我并没有发现这和正常情况有什么区别
A: John Riddoch <jr@scms.rgu.ac.uk>
在这种目录下创建新文件时将采用setgid设置对应的属组,比如
$ ls -ld b
drwxrws--- 2 jr group 512 Mar 14 17:13 b/
$ touch b/a
$ ls -l b/a
-rw------- 1 jr group 0 Mar 14 17:13 b/a
$ id
uid=178(jr) gid=10(staff)
jr的缺省组是staff,而现在b/a文件属组是group。
D: 小四 <scz@nsfocus.com>
SPARC/Solaris 7下测试
如果目录拥有SGID设置,那么该目录下新创建的文件将继承该目录的属组,而不是创
建者所对应的GID。
[root@ /export/home/scz]> id
uid=0(root) gid=1(other) <-- 注意当前用户的属组
[root@ /export/home/scz]> mkdir groupsgid
[root@ /export/home/scz]> ls -ld groupsgid
drwxr-xr-x root other groupsgid/
[root@ /export/home/scz]> chown scz:users groupsgid
[root@ /export/home/scz]> chmod g+s groupsgid
[root@ /export/home/scz]> ls -ld groupsgid
drwxr-sr-x scz users groupsgid/ <-- 目录拥有SGID设置
[root@ /export/home/scz]> cd groupsgid/
[root@ /export/home/scz/groupsgid]> touch scz_0
[root@ /export/home/scz/groupsgid]> ls -l scz_0
-rw-r--r-- root users scz_0 <-- 注意属组变化
[root@ /export/home/scz/groupsgid]> chmod g-s ../groupsgid/
[root@ /export/home/scz/groupsgid]> ls -ld ../groupsgid/
drwxr-xr-x scz users ../groupsgid/
[root@ /export/home/scz/groupsgid]> touch scz_1
[root@ /export/home/scz/groupsgid]> ls -l scz_1
-rw-r--r-- root other scz_1 <-- 注意属组变化
[root@ /export/home/scz/groupsgid]>
1.7 非Sun Console上有无等价Stop-A的按键
A: neomilev
如果是便携机,尝试alt/break 或者 ctrl/break。如果是vt100终端,尝试F11 或者
break
1.8 如何让一个用户只能ftp而无法telnet
A: 小四 <cloudsky@263.net>
修改该用户在/etc/passwd中的shell为/bin/false,在/etc/shells文件中增加
/bin/false,此时,该用户只能ftp,telnet失败。
1.10 为什么Sun工作站非要输入boot命令才能启动
Q: 我有台Sun工作站,每次开机后停在ok状态下,需要手工输入boot命令才能启动,
现在想避免这种效果,怎么办
A: /usr/sbin/eeprom auto-boot?=true
/usr/sbin/eeprom auto-boot? <-- 查询
A: dengdai@SMTH
进入OBP状态
ok setenv auto-boot? true
ok setenv boot-device disk
反之
ok setenv auto-boot? false
1.11 如何让Solaris识别新增加的硬件
Q: 比如新增加了网卡、硬盘、光驱什么的,如何让Solaris意识到这种增加
A: spp(低音炮) & suxm <suxm@gnuchina.org>
有三种办法
a. Stop-A进入OBP状态,输入boot -r
b. sync(重复);reboot -- -r
c. touch /reconfigure;sync(重复);reboot
参看reboot(1M)、boot(1M)、eeprom(1M)、kernel(1M)、cfgadm(1M)、psradm(1M)手
册页
Q: 我新增加了一块硬盘,不想boot -r而立即生效,怎么办
A: 老大 <willxu@public.cs.hn.cn> 2001-12-04 16:51
直接将第二块硬盘接上去,然后顺序执行如下命令,不用重新启动机器
modunload -i 0
drvconfig(1M)
devlinks(1M)
disks(1M)
如果需要重新格式化、分区、创建文件系统,就继续执行
format(1M)
newfs(1M)
2. 堆栈相关问题
2.1 如何理解pstack的输出信息
Q: 080603a7 main (1, 80479b8, 80479c0) + d53
结尾的d53是什么
A: Roger A. Faulkner <raf@sunraf.Sun.COM>
在代码段绝对地址0x080603a7处,main()调用了一个函数,0x080603a7正是
main + 0xd53,换句话说,从main()函数开始的0xd53偏移处。
2.3 Solaris中如何获取一个C程序的调用栈回溯
Q: 我想在Solaris 2.6极其后续版本上获取一个C程序的调用栈回溯,类似如下输出
(10) 0x00045e08 integ + 0x408 [./two_brn.e]
(11) 0x0006468c trajcem + 0x128 [./two_brn.e]
(12) 0x00055490 fly_traj + 0xf58 [./two_brn.e]
(13) 0x0004052c top_level + 0x14 [./two_brn.e]
(14) 0x000567e4 _start + 0x34 [./two_brn.e]
这样我就可以知道当程序崩溃、死锁的时候代码执行到了何处。在HP-UX和IRIX上
可以利用U_STACK_TRACE()和trace_back_stack_and_print(),Solaris上呢?
Q: 有没有办法显示当前堆栈中的数据(GNU/Linux系统)?我希望自己的异常处理程序
在进程结束前dump整个栈区(stack),以便观察到栈顶是什么函数。对于调试意想
不到的运行时错误而言,这很重要。
A: Bjorn Reese <breese@mail1.stofanet.dk>
用/usr/proc/bin/pstack [-F] <pid ...>
参看这个例子代码,http://home1.stofanet.dk/breese/debug/debug.tar.gz
Q: is there a way to access call stack information at run time from within
a program? i've been maintaining my own crude stack using __FUNCTION__
and linked lists but can't help but think there's gotta be a better
way...
A: Nate Eldredge <neldredge@hmc.edu>
这依赖于你的系统,如果使用glibc 2.1或更新版本,可以使用backtrace()函数,
参看<execinfo.h>,其他系统可能有不同的技术支持。
注意,你所使用的办法可能是唯一能够保证跨平台使用的
A: Andrew Gabriel <andrew@cucumber.demon.co.uk> Consultant Software Engineer
下面是一个backtrace()的应用举例,如果你使用Solaris 2.4及其后续版本,那
么这个例子可以很好的工作。很可能无法工作在64-bit模式下,我没有尝试过,
好像Solaris 7已经提供了一个类似的演示程序。还可以增加某些功能,我没有时
间了。
/*
* Produce a stack trace for Solaris systems.
*
* Copyright (C) 1995-1998 Andrew Gabriel <andrew@cucumber.demon.co.uk>
* Parts derived from Usenet postings of Bart Smaalders and Casper Dik.
*
*/
/* ......................................................................... */
#include <setjmp.h>
#include <sys/types.h>
#include <sys/reg.h>
#include <sys/frame.h>
#include <dlfcn.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#if defined(sparc) || defined(__sparc)
#define FLUSHWIN() asm("ta 3");
#define FRAME_PTR_INDEX 1
#define SKIP_FRAMES 0
#endif
#if defined(i386) || defined(__i386)
#define FLUSHWIN()
#define FRAME_PTR_INDEX 3
#define SKIP_FRAMES 1
#endif
#if defined(ppc) || defined(__ppc)
#define FLUSHWIN()
#define FRAME_PTR_INDEX 0
#define SKIP_FRAMES 2
#endif
/* ......................................................................... */
static void print_address ( void * pc )
{
Dl_info info;
if ( dladdr( pc, &info ) == 0 )
{
/* not found */
fprintf( stderr, "*** %s:0x%x\n", "??", ( unsigned int )pc );
}
else
{
/* found */
fprintf( stderr, "*** %s:%s+0x%x\n", info.dli_fname, info.dli_sname,
( unsigned int )pc - ( unsigned int )info.dli_saddr );
}
return;
} /* end of print_address */
/* ......................................................................... */
static int validaddr ( void * addr )
{
static long pagemask = -1;
char c;
if ( pagemask == -1 )
{
pagemask = ~( sysconf( _SC_PAGESIZE ) - 1 );
}
addr = ( void * )( ( long )addr & pagemask );
if ( mincore( ( char * )addr, 1, &c ) == -1 && errno == ENOMEM )
{
return 0; /* invalid */
}
else
{
return 1; /* valid */
}
} /* end of validaddr */
/* ......................................................................... */
/*
* this function walks up call stack, calling print_addess
* once for each stack frame, passing the pc as the argument.
*/
static void print_stack ( void )
{
struct frame * sp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -