检查打开文件句柄不够的原因

最近被 一个打开文件 后没有关闭 的问题 恶心了

以前 我从来 都懒得 关闭 文件

在这个教训后 我决定 认真检查文件关闭

首先就是 发生句柄不够的应用 不一定 是坏蛋

可能是 其他人 吃光了句柄 正好 这个应用不够了

如何检查呢

lsof -p 进程号  看进程开了多少 文件

如果 某个文件 特别多 那就是怀疑的对象

strace -f -e trace=socket,open,close,shutdown -q -p 进程号

来观察 open 和 close是不是 配对出现

而且 句柄 id是不是 暴涨

感谢 这次问题中 同学们 的帮助

Read More

ubuntu compiz 标题栏丢失 的原因

自 8.04以来 偶尔出现的 compiz 3d后标题栏 丢失 让我 脑袋疼死了

9.10 突然爆发了以下 以前 重新设置 3d效果就可以恢复的 东西 无路如何 页无法恢复

最让人感觉像的就是 显卡 问题

不过 突然 失效 不太合理

按 论坛上 关于 增加 xorg.conf中配置项的方式 当然 无法解决问题

后来 就把 问题集中到 compiz 上

重装 卸载都不能解决

但是 一个突破就是 compiz –replace 可以解决 这个问题

加到启动项里边 就好了

现象上看 大概是 compiz 第一次煤没有 启动成功

后来一些悲剧原因 重装 ubuntu了 autostart 当然也没有了

10.10 今天 居然 又出这个 问题了

不过 这次我准备彻底解决问题拉

没有添加 compiz –replace

现象就是 compiz 不起动 后来 发现 compiz 是一种 gtk-window-decorator (理解不完全正确)

gtk-window-decorator –replace 居然可以达到同样效果

就更确认 是由于 一些原因导致了 那个东西没有启动

后来发现 /usr/bin/gnome-wm 是启动 decorator 的东西

就 修改脚本 打了 一些日志 发现 gnome启动  根本 没有执行 gnome-wm

这样 问题 本质 找到了 不过 想不出来 为什么 他没有执行

于是 google 发现了国际友人

http://ubuntuforums.org/showpost.php?p=7610738&postcount=4

I found the source of the problem, and it’s pretty easy to fix. Very non-intuitive to find, though.

At some point gnome-session switched from using regular commands to using .desktop launchers for launching things like the panel and window manager. It looks for these files in a few locations, including/usr/share/applications and $HOME/.local/share/applications.

It also appears that alacarte (the menu application), or possibly just the freedesktop.org specification for menus, uses $HOME/.local/share/applications for user-specific menu customizations.

For whatever reason, a copy of /usr/share/applications/gnome-wm.desktop was made in my $HOME/.local/share/applications directory which I suspect added Window Manager in my menu somewhere. I’m pretty anal about keeping my menus clean of stuff I don’t use, so I would have gone in and disabled that entry which changed the Hidden setting in my fancy new $HOME/.local/share/applications/gnome-wm.desktop file to True.

The last piece of the puzzle is that gnome-session stops searching after it finds an appropriate file, but it also doesn’t run a launcher if it’s hidden, so it was just straight-up skipping that step.

There are two ways to fix it, according to your preference:

  • Change the Hidden setting in $HOME/.local/share/applications/gnome-wm.desktop to false. This will (probably) put a Window Manager item in your applications menu somewhere.
  • Remove $HOME/.local/share/applications/gnome-wm.desktop entirely so that gnome-session has to find it elsewhere. If you’re gonna do this, make sure you check for Window Manager (or gnome-wm.desktop) in /usr/share/applications first.

This should work for the gnome-session panel and file manager, too.

New user notes:

  • $HOME refers to your home directory, which is /home/yourusername. My sister qualifies as a new user, and she said she may not have been able to figure that out right away.
  • To find $HOME/.local/share/applications using the file browser, you’ll need to show hidden files, since .local is hidden.
  • Launcher files (like gnome-wm.desktop) are generally listed in the file browser by a name they declare, rather than their file name. This particular file will probably be called Window Manager

回忆一下 昨天 蛋疼 改动过 菜单项……

按照 方案 解决问题

为什么 不能 compiz –replace

第一感觉 就是 不是最佳 解决方案

这里 还有 解释

http://www.jejik.com/articles/2008/10/how_to_properly_start_compiz_in_gnome/

Read More

JBoss 中文乱码的一些解决方案

前提 GBK 编码
其他 可以参考

* 给系统加 Lang = zh_CN.GBK …

如果不行

* 强制JVM编码

/bin/run.conf +

JAVA_OPTS=”$JAVA_OPTS -Dsun.jnu.encoding=GBK -Dfile.encoding=GBK”

如果还不行

* 强制过滤器 web.xml


encodingFilter
org.springframework.web.filter.CharacterEncodingFilter

encoding GBK

forceEncoding true



encodingFilter
/*

我靠 有才 还不行

* 强制 URI编码

tomcat 的恶 server.xml

还不行……
改用英文程序把 不会有问题

Read More

svn 解锁经历

今天对代码进行了一次巨大的清理

移动 删除和 改动了 很多代码

提交之后 …… 突然 svn 提示锁了

svn st 一下发现 代码全都 多了个 L

一下子就蒙了

第一反应是 svn cleanup

结果提示 无法解锁

开始发现了一个 svn unlock 命令 存扯蛋 命令……

后来发现文件能单个 cleanup

就说明是某些文件无法 cleanup

然后就 一个一个实验 最后剩下了 4个目录 无法解锁

发现都是 带有 A D这样的

然后就进目录一个一个 cleanup

发现居然能提示 无法cleanup的原因了 一个文件丢了

touch 一下 解决

L 都处理掉之后 svn up了发现有一些 ~

就svn up了一下 不让up

就把 ~ 的都 D了

这次让up了 D的 都变成 C了

这就好办了 revert 就可以了

svn up 之后发现 虽然本地lock了

但是 代码都被成功提交了………………

所以 最简单的办法是 重新 co

不过 还是总结了一些经验

不能 rm 和 svn rm 或者 mv 一起用 尽量用svn rm

跨目录这样的mv 能避免就避免 引起锁的 坏蛋

Read More

在ubuntu 上使用virtualbox 的usb

文章还是美帝的好用

https://help.ubuntu.com/community/VirtualBox/USB

这篇文章还为懒人准备了脚本

总结下无法开启usb问题所在

ubuntu的源中 virtualbox是ose的
就是 open source edition

而 ose 是不支持 usb的 不管你怎么折腾 也是无法开启usb的

解决方法就是 从官方网站 装一个 non-free的版本

http://www.virtualbox.org/wiki/Linux_Downloads

装完后将
将 自己 加入 vboxusers 组

1
 if [ "`grep vboxusers /etc/group|grep $USER`" == "" ] ; then sudo usermod -G vboxusers -a $USER ; fi

vboxusers 的 gid 对usb的 读写 加到 /etc/fstab
原理就是在 fstab加一个
none /proc/bus/usb usbfs devgid= vboxusers 组的id ,devmode=664 0 0

none /proc/bus/usb usbfs devgid=124,devmode=664 0 0

美帝还为懒人准备的脚本

1
2
3
4
5
6
7
8
9
10
#Enter a root shell, eg
 sudo -i

# In that shell, set up /etc/fstab

 vGid="`grep vboxusers /etc/group|cut -d\: -f3`" # Determine the devgid for the vboxusers group
 if [ "$vGid" ] && [ "`grep usbfs /etc/fstab`" == "" ] ; then
        echo "none /proc/bus/usb usbfs devgid=${vGid},devmode=664 0 0" >>/etc/fstab
        mount -a
 fi
Read More

Apache配置引起的IE6下载zip损坏

今天遇到一个奇怪的问题
IE6 下载的zip包 无法打开
Firefox没问题

QA姐姐用非常变态的 IE6 浏览器
我开始还不相信 后来自己尝试了以下 果然有这个问题

IE 果然是神级浏览器
突然发现 损坏的压缩包 可以用7z打开
进一步发现 损坏的压缩包 是一个 .gz 文件

一切就清晰了
原来IE6有bug

apache中配置了
SetOutputFilter DEFLATE
这个 引起了下载问题

改为
AddOutputFilterByType DEFLATE text/html text/plain text/xml
问题解决

Read More

入门级别linux socket 通信

linux 进程间通讯 第一步

主要是参考 http://beej.us/guide/bgipc/ 写出来的
国人写的基本全是转载 不是代码残疾 就是根本看不懂的……广告

整理下 g++编译

Server.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
using namespace std;

#include <sys/socket.h>
#include <sys/un.h>

const int MAX_RECV = 500;

int main(int argc, char ** argv){

    sockaddr_un server; // sockaddr_un 表示使用socket文件 参考 sockaddr_in

    server.sun_family = AF_UNIX;
    strcpy(server.sun_path, "test.socket");
    unlink(server.sun_path); // 绑定之前 清理掉 

    int s = socket(AF_UNIX, SOCK_STREAM, 0);

    bind(s , (sockaddr *) &server, sizeof(server));

    listen(s, 5);
   
    for(;;){
        cout<<"Wating"<<endl;

        sockaddr_un client;
        socklen_t client_len = sizeof(client);

        int c = accept(s, (sockaddr *) &client, &client_len);
        cout<<"Connected " <<endl;

        char buf[MAX_RECV];
        int len;

        while( (len = recv(c, &buf, MAX_RECV, 0)) >0 ){
            // 处理buf

            cout <<"Client Says:" << buf <<endl;
            send(c, buf, len, 0); //写入client
        }
    }

    return 0;
}

client.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
using namespace std;

#include <sys/socket.h>
#include <sys/un.h>

const int MAX_RECV = 500;

int main(int argc, char ** argv){
   
    sockaddr_un server; // sockaddr_un 表示使用socket文件 参考 sockaddr_in

    server.sun_family = AF_UNIX;
    strcpy(server.sun_path, "test.socket");

    int s = socket(AF_UNIX, SOCK_STREAM, 0);

    connect(s, (sockaddr *) &server, sizeof(server));

    char str[MAX_RECV];
    char buf[MAX_RECV];

    while(cin>>str){
        send(s, str, sizeof(str), 0);

        if( recv(s, &buf, MAX_RECV, 0) >0 ){
            // 处理buf
            cout << "Server Say:" << buf <<endl;
        }

    }
    return 0;
}

Makefile

1
2
3
4
5
6
7
all: server client
   
server: server.cpp
    g++ -o server server.cpp

client: client.cpp
    g++ -o client client.cpp
Read More

Mac Windows Linux 爱好者眼中的对方

Read More

ubuntu 挂了又复活的一次经历

今天 拿到了 ubuntu寄来的光盘 很兴奋

回家 apt-get up了以下

发现内核升级了2.6.31-14 -> 2.6.31-15

没多想 反正apt么 结果 机器启动不起来了
症状是屏幕狂闪 不能进X

后来 在启动的时候 按Shift进 菜单

选原来 -14 的内核 发现果然能启动

然后去看dmesg log

发现 -14 合 nv 驱动 不兼容

卸载nv驱动 果然 -15内核可以启动了

然后 在15上重新build nv驱动

问题解决……

惊现 惊险

Read More

sudo 很慢

新配机器发现sudo 很慢

经查 资料发现

是 hostname 没有在 /etc/hosts 中的原因

修正后解决

Read More