c - close() after system() weird behavior -


i'm calling system("bash ../tools/bashscript \"this argument!\" &"), i'm calling close(socketfd) directly after system returns, of course i've read system's argument appended & fork command, system returns , i've checked that!

now problem don't want socket stay connected while command being executed, weirdest thing work flow of program continues , close seen , overlooked , once command finishes close takes effect!

i tried call close twice after each others make sure delete every copy of socketfd if created, still same problem, don't know why close being called doesn't take effect until command (the bash script) finishes!

please advise!

i'm little confused you're doing, system thin wrapper on fork. means both processes have copies* of socket descriptor, , 1 "copy" closed. other persists until forked process in system command executing terminates well.

why not close socket before call system?

you try using shutdown on dup'd descriptors, e.g.:

shutdown(s,shut_rdwr); 

*tthe rules around happens file , socket descriptors through fork calls little more subtle "copying", sufficient explain why it's not working you.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -