新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
#include
#include
#include
#include
#include
int main(){
pid_t pid;
pid = fork();
if(pid <0 ){
std::cout<< "fork error!"<
}
//父子进程都执行
redisContext* conn = redisConnect("10.1.175.130", 6379);
if(NULL==conn || conn->err){
if(conn){
std::cout<<"Error:"<
redisFree(conn);
} else {
std::cout<<"Error:Can't allocate redis context"<
}
return 0;
}
if(0==pid){
const char* command = "set name yuanzaixin";
redisReply* r = (redisReply*)redisCommand(conn, command);
if(NULL==r){
redisFree(conn);
return 0;
}
std::cout<<"fork child"<
}
if(pid >0){
//父进程执行不一样的命令
const char* command = "set name xinzaiyuan";
redisReply* r = (redisReply*)redisCommand(conn, command);
if(NULL==r){
redisFree(conn);
return 0;
}
std::cout<<"fork parent"<
}
//父子进程都执行
if (NULL!=conn){
redisFree(conn);
}
}