LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Is it possible to use file descriptor after main returns (https://www.linuxquestions.org/questions/programming-9/is-it-possible-to-use-file-descriptor-after-main-returns-720859/)

arun.raj 04-22-2009 03:36 AM

Is it possible to use file descriptor after main returns
 
Hello All,

I want to use the file descriptor opened by application_1 in another application_2, i.e

./application_1 :
main()
{
fd_1 = open( file );
return fd_1;
}

./application_2 fd_1
main()
{
ret = read( fd_1 );
return fd;
}

My concern is once application_1 main returns all open fds will be closed right ?

Thanks in advance .

Thanks,

Sergei Steshenko 04-22-2009 05:24 AM

Do you want to organize IPC (Inter-Process-Communications) ?

bigearsbilly 04-22-2009 06:10 AM

of course.
all files are closed on exit.

jisjis 04-23-2009 06:24 AM

Quote:

Originally Posted by arun.raj (Post 3517015)
Hello All,

I want to use the file descriptor opened by application_1 in another application_2, i.e

./application_1 :
main()
{
fd_1 = open( file );
return fd_1;
}

./application_2 fd_1
main()
{
ret = read( fd_1 );
return fd;
}

My concern is once application_1 main returns all open fds will be closed right ?

Thanks in advance .

Thanks,



Why dont you write the fd_1 = open( file ); bit in your application_2 itself ?

Linux


All times are GMT -5. The time now is 06:07 AM.