unix

How do I determine if a terminal is color-capable?

旧时模样 提交于 2020-01-20 01:35:01
问题 I would like to change a program to automatically detect whether a terminal is color-capable or not, so when I run said program from within a non-color capable terminal (say M-x shell in (X)Emacs), color is automatically turned off. I don't want to hardcode the program to detect TERM={emacs,dumb}. I am thinking that termcap/terminfo should be able to help with this, but so far I've only managed to cobble together this (n)curses-using snippet of code, which fails badly when it can't find the

python基础——socket

人盡茶涼 提交于 2020-01-19 03:48:20
一.socket概念 1.理解socket 络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket。 建立网络通信连接至少要一对端口号(socket)。socket本质是编程接口(API),对TCP/IP的封装,TCP/IP也要提供可 供程序员做网络开发所用的接口,这就是Socket编程接口;HTTP是轿车,提供了封装或者显示数据的具体形式; Socket是发动机,提供了网络通信的能力。 Socket的英文原义是“孔”或“插座”。作为BSD UNIX的进程通信机制,取后一种意思。通常也称作"套接字",用于描述 IP地址和端口,是一个通信链的句柄,可以用来实现不同虚拟机或不同计算机之间的通信。在Internet上的主机一般运 行了多个服务软件,同时提供几种服务。每种服务都打开一个Socket,并绑定到一个端口上,不同的端口对应于不同 的服务。Socket正如其英文原义那样,像一个多孔插座。一台主机犹如布满各种插座的房间,每个插座有一个编号, 有的插座提供220伏交流电, 有的提供110伏交流电,有的则提供有线电视节目。 客户软件将插头插到不同编号的插座, 就可以得到不同的服务。 Socket是应用层与 TCP/IP协议族通信的中间软件抽象层,它是一组接口。在设计模式中, Socket其实就是一个门面模式, 它把复杂的 TCP/IP协议族隐藏在

PHP-MYSQL时间

血红的双手。 提交于 2020-01-19 03:03:08
Unix 时间戳 Unix timestamp ('1970-01-01 00:00:00' GMT 之后的秒数) MySQL: FROM_UNIXTIME () 给定一个Unix 时间戳 (可以是 字段名 ,也可以直接是Unix 时间戳字符串),返回格式化日期 例如: mysql>SELECT FROM_UNIXTIME( 1394972228, '%Y%m%d' ) ->20140316 mysql>SELECT FROM_UNIXTIME( 1394972228, '%Y年%m月%d日' ) ->2014年03月16 使用 FROM_UNIXTIME函数,具体如下: FROM_UNIXTIME(unix_timestamp,format) 返回表示 Unix 时间标记的一个字符串,根据format字符串格式化。format可以包含与DATE_FORMAT()函数列出的条目同样的修饰符。 根据format字符串格式化date值。下列修饰符可以被用在format字符串中: %M 月名字(January……December) %W 星期名字(Sunday……Saturday) %D 有英语前缀的月份的日期(1st, 2nd, 3rd, 等等。) %Y 年, 数字, 4 位 %y 年, 数字, 2 位 %a 缩写的星期名字(Sun……Sat) %d 月份中的天数, 数字(00……31

fork() and output

限于喜欢 提交于 2020-01-18 15:49:47
问题 I have a simple program: int main() { std::cout << " Hello World"; fork(); } After the program executes my output is: Hello World Hello World . Why does this happen instead of a single Hello world ? I'm guessing that the child process is rerun behind the scenes and the output buffer is shared between the processes or something along those lines, but is that the case or is something else happening? 回答1: This isn't quite what you thought originally. The output buffer is not shared - when you

fork() and output

穿精又带淫゛_ 提交于 2020-01-18 15:49:45
问题 I have a simple program: int main() { std::cout << " Hello World"; fork(); } After the program executes my output is: Hello World Hello World . Why does this happen instead of a single Hello world ? I'm guessing that the child process is rerun behind the scenes and the output buffer is shared between the processes or something along those lines, but is that the case or is something else happening? 回答1: This isn't quite what you thought originally. The output buffer is not shared - when you

unix domain socket的性能测试

百般思念 提交于 2020-01-18 02:42:02
背景说明 最近在做的一个项目,底层是用以前C写的语音交换能力,由于语音的应用需要对流进行处理,这边为了对接网络或者应用方便,想把流桥接出来,在能力层上面封装一层业务,同时又不想影响以前的流程。 所以一直在考虑进程内通信的问题,组件的话本身以前一直用event socket lib开发也没什么问题,但是之前都是用来做信令控制而已,负载并不高。 这次桥接的语音流初步目标是1000路并发,最少的8K采1000路就是每秒8m,就算单路每秒发25次数据,每次320字节,那每秒网卡那边中断次数也是2w+,这个对并发是一个巨大的挑战。 之前event socket lib开发虽然也是对接1000路,但是总归每秒的请求也就平均一个上下,而且数据量小。 这次我想反正这两个组件暂时不会分开,干脆就进程间通信好了。消息队列共享内存什么的我就不考虑了,因为我写东西比较习惯抽象的接口,考虑到后面流更大了后,微服务模块可能会开发一个强大的硬解模块来解决,也希望兼容网络通信的写法,所以选定了unix domain socket,毕竟接口和写net socket没什么区别。 unix domain socket相对网络通信用于 IPC 更有效率:不需要经过网络协议栈,不需要打包拆包、计算校验和、维护序号和应答等,只是将应用层数据从一个进程拷贝到另一个进程。这是因为,IPC 机制本质上是可靠的通讯

Store Data from Field as a txt file on server (javascript)

和自甴很熟 提交于 2020-01-17 15:23:31
问题 Im trying to upload a plain text file to a server from my javascript form. When you hit submit, I need to store a text file on my server so that my translator program can read the file. Please see my project and it will make sense Link to my project 回答1: Can't you just submit the form holding the text value and generate the text file on the server? 来源: https://stackoverflow.com/questions/15890617/store-data-from-field-as-a-txt-file-on-server-javascript

解决“/bin/bash^M: bad interpreter: No such file or directory”

半世苍凉 提交于 2020-01-17 14:54:40
在执行shell脚本时提示这样的错误主要是由于shell脚本文件是dos格式,即每一行结尾以\r\n来标识,而unix格式的文件行尾则以\n来标识。 查看脚本文件是dos格式还是unix格式的几种办法。 (1) 查看脚本的格式: cat -A filename 从显示结果可以判断,dos格式的文件行尾为^M$,unix格式的文件行尾为$。 (2) 修改脚本的格式:vi filename打开文件,执行 : set ff=unix 设置文件为unix,然后执行:wq,保存成unix格式。 (3) 查看脚本的格式: cat -A filename 从显示结果可以判断,dos格式的文件行尾为^M$,unix格式的文件行尾为$。 来源: https://www.cnblogs.com/YangGC/p/12205415.html

Why the program didn't execute some sentences in this C programming or unix programming(execvp() System calls)?

假装没事ソ 提交于 2020-01-17 12:40:45
问题 I have the following program, when I run the program, I feel really confused that why my program didn't excute int num=i; printf("it is No.%d !",num); printf("hello , I will excute execvp!"); My program basically create 6 child processes to excute executionbode() function, and then use execvp to overload original program. However, everytime when I run the program, the string "hello, I will execute execvp" never shows up! Also I think those three sentences above also didn't execute in the

Fetch data from Oracle SP Out Param SYS_REFCURSOR in Unix Korn Shell Script

拟墨画扇 提交于 2020-01-17 07:13:05
问题 I have a stored procedure in oracle with out parameter as sys ref_cursor. I need to execute the sp from korn shell . read the output and use it as a email body. But i could not find any example code to read sys ref cursor in unix. below is my code. Also how can i read cur ? print cur doesnt seem to print any output. #!/usr/bin/ksh function runproc { #read ref cursor from proc cur=`sqlplus -s $connectiondetails <<EOF SET PAGESIZE 0 FEEDBACK ON VERIFY OFF HEADING OFF ECHO OFF var return_val ;