操作环境
SuSE10/SuSE11
问题现象
执行userdel -rf oracle删除用户失败,提示userdel: user 'oracle' is currently logged in
问题分析
NA
问题解决
1、ps -fu oracle查看是否还有进程在使用(也可以使用ps -ef |grep 'oracle'| grep -v grep),如果有进程在使用。kill掉相关进程
2 、重新执行userdel -rf oracle,如果失败,则执行步骤3
3、删除 /var/run/utmp文件。cd /var/run; mv utmp utmp_bak;touch utmp
4、重新执行userdel -rf oracle。
知识延伸
为什么删除utmp文件就可以执行删除用户成功?查看如下函数信息
/var/run/utmp database of currently logged-in users
src/userdel.c if(is_logged_in(remove_user)) { fprintf(stderr,_("%s:account '%s' is currently in use. ")),program,remove_user); return E_USER_BUSY; } lib/is_logged_in.c /* Check if the user is logged in. 0:user is not logged in 1:user is logged in */ int is_logged_in(const char *user) { struct utmp *utp; setutent(); while((utp = getutent())) { if(utp->ut_type == USER_PROCESS && strncmp(utp->ut_user,user,sizeof utp->ut_user)==0) return 1 } return 0 }