일련의 프로세스 식별자와 일부 상태 정보가 포함 된 이중 연결 목록이있는 파일이 있습니다.C 프로그래밍 연결된 목록 및 제거
{
struct pr7_process *cur;
for(cur = list->head; cur != NULL; cur = cur->next)
{
if (cur->pid == pid)
{
printf("cur pid: %d\n", cur->pid);
cur->state = STATE_NONE;
if(list->head == list->tail)
{
free(cur);
}
else
{
cur->prev->next = cur->next;
cur->next->prev = cur->prev;
free(cur);
}
break;
}
}
}
내 제거 기능에 어떤 문제가 :
struct pr7_process
{
pid_t pid; /* process ID, supplied from fork() */
/* if 0, this entry is currently not in use */
int state; /* process state, your own definition */
int exit_status; /* supplied from wait() if process has finished */
struct pr7_process *next; // a pointer to the next process
struct pr7_process *prev;
};
/* the process list */
struct process_list
{
struct pr7_process *head;
struct pr7_process *tail;
};
내 목록의 요소를 제거하는 방법이 있나요? 내 목록을 인쇄하려고 할 때 무한 루프가 발생하는 것 같습니다. 이전에 나는 그것이 무료()를 사용하는 방법이라고 생각했지만 응답에서 분명히 아니었다. :)
고마워!
: 즉 같은 뭔가를 구축 감안할. –
** 어떻게 ** 할당 되었습니까? –