char * of_program_name= "./AB";
1、 pid = getPidFromName(of_program_name);
if (pid > 0)
{
ERROR("AB process still exispid = %d\n", pid);
if (kill(pid, SIGKILL)) //杀死进程
{
fprintf(stderr, "kill(SIGKILL)error\n");
continue;
}
wait(NULL);
}
2、重启另外一个进程
if (0 == fork())
{
ERROR("start ABagain\n");
if (execl(of_program_name, of_program_name, NULL))
{
fprintf(stderr, "exec %s error\n", of_program_name);
}
}
usleep(100000);
}
3、//关闭共享内存
if (shmctl(shmid, IPC_RMID, 0) == -1)
{
fprintf(stderr, "shmctl(IPC_RMID) failed\n");
exit(EXIT_FAILURE);
}
4、 //share memory initialzie
void* shm = NULL;
struct shared_use_st* shared = NULL;
int shmid;
//get share memory
shmid = shmget((key_t)6666, sizeof(struct shared_use_st), 0666 | IPC_CREAT);
if (shmid == -1)
{
fprintf(stderr, "shmget failed\n");
exit(EXIT_FAILURE);
}
// map the share memory to local address
shm = shmat(shmid, (void*)0, 0);
if (shm == (void*) -1)
{
fprintf(stderr, "shmat failed\n");
exit(EXIT_FAILURE);
}
shared = (struct shared_use_st*)shm;