pclose problem, bei pthreads

Ich hab in einem Modul folgende Funktionsanordnung

Code:
void*hdd_cycles_handler(void*arg)
{
	FILE*hdd_cycles_pipe;
	hdd_cycles_pipe=popen("iotop -obtq", "r");
	
	char buff[512];
	while (fgets(buff, sizeof(buff), hdd_cycles_pipe) != NULL)
	{
		FILE*writing_file=fopen(monitoring_files[0], "a");
		fputs(buff, writing_file);
		fclose(writing_file);
	}
	return 0;
}

int monitoring_hdd_cycles_start()
{
	pthread_create(&hdd_cycles_trd, NULL, hdd_cycles_handler, NULL);
	return 0;
}


int monitoring_hdd_cycles_stop()
{
	pthread_cancel(hdd_cycles_trd);
	
	return 0;
}

Das funktioniert auch wunderbar so, bis allerdings sich das Hauptprogramm beendet. Dann kommen fette Pipe Error

Code:
Traceback (most recent call last):
  File "/usr/bin/iotop", line 16, in <module>
    main()
  File "/usr/lib/pymodules/python2.6/iotop/ui.py", line 547, in main
    main_loop()
  File "/usr/lib/pymodules/python2.6/iotop/ui.py", line 537, in <lambda>
    main_loop = lambda: run_iotop(options)
  File "/usr/lib/pymodules/python2.6/iotop/ui.py", line 450, in run_iotop
    return run_iotop_window(None, options)
  File "/usr/lib/pymodules/python2.6/iotop/ui.py", line 446, in run_iotop_window
    ui.run()
  File "/usr/lib/pymodules/python2.6/iotop/ui.py", line 126, in run
    self.process_list.duration)
  File "/usr/lib/pymodules/python2.6/iotop/ui.py", line 406, in refresh_display
    sys.stdout.flush()
IOError: [Errno 32] Datenübergabe unterbrochen (broken pipe)

Ich schätze mal das liegt daran, das die pipe irgendwo vorher geschlossen werden muss. Aber wie kann ich das anstellen? ich müsste ja bevor der Thread gecancelt wird ein pclose aufrufen, hab schon einiges probiert. Komme nicht auf die Lösung

Danke
 
Zurück
Oben