Hackerboard Wiki HaboBlog
Hackerboard bei Facebook Hackerboard bei Google+ Hackerboard bei Twitter

[HaBo]

 
Code Kitchen Allgemeines Coder-Forum rund um das Programmieren eigenständiger, ausführbarer Programme.

pclose problem, bei pthreads

Diskussion: pclose problem, bei pthreads im Forum Code Kitchen, in der Kategorie Software Home; Anzeige 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), ...

Antwort
Alt 05.02.11, 16:41   #1 (permalink)
 
Registriert seit: 25.11.06
gugugs Leistung: Facit NTK
Likes: 0
Standard pclose problem, bei pthreads

Anzeige

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
gugugs ist offline   Mit Zitat antworten
Antwort
   
- Anzeige -

Werbung ist gerade online    

[HaBo] » Software Home » Code Kitchen » pclose problem, bei pthreads
Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind aus
Pingbacks sind aus
Refbacks sind aus



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61