zoukankan      html  css  js  c++  java
  • Linux笔记

    # 如何在shell脚本中获取自己的绝对路径?

    basepath=$(cd `dirname $0`; pwd)

    如果脚本文件是软连接,则

    basepath=`dirname $(readlink $0)`

    # 如何通过pid获取某个进程的stdout?

    cat /proc/$pid/fd/1

    # 如何用程序启动一个进程并获取它的标准输出?

    用popen。

    #include <stdio.h>
    #include <string.h>
    
    char buf[1024];
    memset(buf, 0, sizeof(buf));
    FILE *fp = popen("alsaplayer --status", "r");
    fread(buf, sizeof(char), sizeof(buf) - 1, fp);
    pclose(fp);
    View Code

    # 在cgi程序中使用system()出现的权限问题的解决

    apache web server给cgi程序分配的用户权限较低,在cgi程序中使用system()函数时会返回256错误。

    解决方法:

    假设要在system中启动alsaplayer,则需首先在shell中执行

    sudo chmod +s /usr/bin/alsaplayer

    然后在cgi程序中执行

    system("alsaplayer");

    就能成功了。

    # 当宿主机网络发生变化时,如果linux虚拟机的网络没有自动随着变化,则需要在linux虚拟机里执行:

    sudo

    ifconfig eth0 down
    ifconfig eth0 up
    dhclient eth0

  • 相关阅读:
    html集合
    pyautocad
    CAD 批量提取点坐标,实现坐标的快速提取
    CAD
    python模块
    set,get,setter
    1 Http的表皮
    (6)小项目------完善增删改查的操作
    SSM学习笔记(6)---拦截器
    SSM学习笔记(5)-CGLIB动态代理
  • 原文地址:https://www.cnblogs.com/leaf-w/p/3688358.html
Copyright © 2011-2022 走看看