プロセス識別子のセットといくつかの状態情報を含む二重リンクリストを含むファイルがあります。
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;
};
リストの要素を削除する方法があります。
{
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;
}
}
}
削除機能の何が問題になっていますか?リストを印刷しようとすると、無限ループが発生するようです。以前は、free()を使用した方法だと思っていましたが、返信からではないようです:)
ありがとう!