http://bbs.linuxtone.org/threa…
什么是S.M.A.R.T.
SMART是一种磁盘自我分析检测技术,早在90年代末就基本得到了普及
每一块硬盘(包括IDE、SCSI)在运行的时候,都会将自身的若干参数记录下来
这些参数包括型号、容量、温度、密度、扇区、寻道时间、传输、误码率等
硬盘运行了几千小时后,很多内在的物理参数都会…… 阅读全文
Tag Archives: Linux
Linux 多进程监听 socket
首先来看代码
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/wait.h>
int main() {
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd…… 阅读全文
Linux TCP UDP 混合
基本的思路是这样的:在服务器端,有两个机器,一个对外开启 TCP 监听,然后把监听到的请求内容送到后面的另外一台,或者多台轮询机器上,内网之间使用 UDP,然后等待业务逻辑机器处理完成,这个地方可以做成异步的,然后再返回到用户。
即是这样: client server_front server_back
下面来看代码,首先是 server_fro…… 阅读全文
Linux UDP 收发实例
首先我们需要一个 struct.h
#ifndef STRUCT_H
#define STRUCT_H
typedef struct _UDP_MSG {
int add1;
int add2;
int sum;
char str1[128];
char str2[128];
char cat[256];
} UDP_MSG;
#endif /* STRUCT_H */
然后是服务端的
#include <sys/types.h>
#include <…… 阅读全文
共享内存的读写
首先我们需要一个 shm_com.h
#ifndef _SHM_COM_H_
#define _SHM_COM_H_
#define TEXT_SZ 2048
struct shared_use_st {
int written_by_you;
char some_text[TEXT_SZ];
};
#endif /* _SHM_COM_H */
然后是 shm1.cpp
#include <stdio.h>
#include <stdlib.h>
#include <unis…… 阅读全文
[转]一份高质量的 Epoll 服务端代码
来自https://banu.com/blog/2/how-to…,由http://www.oschina.net/transla…提及
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#include <f…… 阅读全文
不同服务器端模型在并发请求下的表现差异
一般来说,服务器的模型有下面几种:
单进程单线程
多进程(一个请求对应一个进程,Apache 之类貌似就是这个)
多线程(一个请求对应一个线程,这个挺少见到的)
select / poll
epoll
它们的差别可以看这个,http://www.cnblogs.com/sharra/…
因为需要了解底层设备访问的原理,所以惯用高层应用语言的我,需要了…… 阅读全文
shell 俄罗斯方块
利用 bash 脚本在 shell 上跑一个俄罗斯方块的游戏,还是挺有意思的,视频讲解在这里,http://v.youku.com/v_show/id_X…,http://v.youku.com/v_show/id_X…,代码的话这里有一份,http://www.chinaunix.net/old_j…,原样照搬过来
#!/bin/bash
# Tetris Game
# 10.21.2003 xhchen<[email]xhch…… 阅读全文
二级指针删除单向链表
今晚在这里看到一篇文章,http://coolshell.cn/articles/8…,原文给的是代码片段,本着动手实践的原则,另外顺便复习一下链表,写了下代码
#include <stdio.h>
#include <stdlib.h>
typedef struct _node {
int n;
struct _node *next;
} node;
typedef int (* remove_fn)(node const *…… 阅读全文
signal 在 c99 下的差异
在写一个 minishell 的时候,需要捕捉从键盘输入的 ctrl+c 产生的 SIGINT 信号,转入自己的处理函数,代码大致如下
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
int shell_loop() {
setup();
COMBINE_COMMAND cmd;
while (1) {
…… 阅读全文