十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
#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);
}
}