piping forking dup2'ing and in the end shooting the pc
Nikos Kouremenos
nk at ebox.gr
Tue Apr 6 18:10:01 EEST 2004
V13 wrote:
> On Tuesday 04 May 2004 14:53, Nikos Kouremenos wrote:
>
>>αυτός ο κώδικας: http://nk.unstable.nl/final.c.html
>>
>>έχει γραψεί αυτόν τον κώδικα: http://nk.unstable.nl/final.c.html
>>με σκοπό να εξομοιώσει το:
>>cat file | gzip -c > file.gz
>>
>>
>>
>>όμως κάπου προς το τέλος μου τα χαλάει.
>>παρότι έχω κάνει νομίζω σωστά χρήση των dup2 τελικά παράγονται broken
>>.gz και λίγο crappy output στην κονσόλα
>
>
> a) To gzip thes na to trekseis mono mia fora kai oxi toses osa read kaneis,
> opote mporeis na ksyloseis olo to while() loop toy child process kai na to
> antikatastiseis me to:
>
> execl("/bin/gzip","gzip", "-fc", NULL);
>
> (hint, meta apo kati tetoio kalo einai na kaneis exit() oste an apotyxei to
> exec na min synexisei to prog ston ypoloipo kodika.
>
> b) To gzip tha grapsei sto stdout, diladi sto fd #1. Esy les:
>
> dup2(1, fd_out)
>
> to opoio den exei kanena apolytos noima. Ayto poy theleis einai:
>
> dup2(fd_out, 1)
>
> oste na klisei to palio stdout kai na to balei to fd_out na einai kai to fd#1
>
> kanontas tis parapano alages moy doylepse gia 50K keimeno.
>
> c) Ta bytes tha prepei na ta metras sto parent process kai oxi sto child giati
> akoma kai an ta metriseis (pragma adynato mias kai kaneis exec() h opoia
> antikathista pliros to process) den tha mporeseis na ta emfaniseis h na ta
> stileis sto parent. O poio eykolos tropos tha itan na kaneis ena stat() to
> arxeio oste na deis to teliko toy megethos.
>
> d) Mipos ayto poy theleis na kaneis einai aplos to 'gzip -v koko' ?
>
>
>>ΥΓ. έχω κάνει και ένα implementation με popen άλλα αυτή είναι πολύ
>>high-level και δεν μπορώ να μετρήσω τα bytes που βγάζει το gzip [εκτός
>>αν κοιτάξω το filesize του fileout.gz που όμως κάτι τέτοιο δεν θέλω]
>
>
> To mono problima poy exei h popen() einai oti mporeis na exeis mono read h
> mono write alla oxi kai ta dyo. Ta bytes stin popen() mporeis na ta metriseis
> metrontas ayta poy perneis apo tin read() (an exeis read).
>
> <<V13>>
>
thanks
o Glynos malos tsatistike. alla ego eiha kollisei agria kai kapou eiha
apelpistei.
se efharisto. nomizo pos o kodikas aftos:
http://www.greekarena.com/nkour/test.c.html
pleon doulevei sosta [etsi pistevo]
eihes dikio gia to dup2 to eiha naapoda :$
oso gia afto:
> c) Ta bytes tha prepei na ta metras sto parent process kai oxi sto
child giati
> akoma kai an ta metriseis (pragma adynato mias kai kaneis exec() h opoia
> antikathista pliros to process) den tha mporeseis na ta emfaniseis h
na ta
> stileis sto parent. O poio eykolos tropos tha itan na kaneis ena
stat() to
> arxeio oste na deis to teliko toy megethos.
ne ehis dikio. tha borousa na kano assign se mia global variable.
ne enoeis oti me tin exec sbinode ola ta locals mou.
tha borusa prin apo afti na to kano assign se mia global
xilia efxaristo..
kathe mera ginome kaliteros [elpizo]
xari se atoma san ki esena kai oxi san ton Glyno [ton opio den xero opos
ki esena alla edaxei katalabeno oti tou erxete saboura pou den theli]
that's why I USERNET this list :P
have fun
More information about the Linux-greek-users
mailing list