LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-22-2009, 03:36 AM   #1
arun.raj
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Rep: Reputation: 0
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,
 
Old 04-22-2009, 05:24 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Do you want to organize IPC (Inter-Process-Communications) ?
 
Old 04-22-2009, 06:10 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
of course.
all files are closed on exit.
 
Old 04-23-2009, 06:24 AM   #4
jisjis
LQ Newbie
 
Registered: Apr 2009
Posts: 18

Rep: Reputation: 0
Quote:
Originally Posted by arun.raj View Post
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

Last edited by jisjis; 04-26-2009 at 04:42 AM.
 
  


Reply

Tags
exit, main


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get the absolute path of file using file descriptor. appas Programming 7 01-19-2012 11:47 AM
Is it possible to use file descriptor after main returns arun.raj Linux - Newbie 1 04-22-2009 03:44 AM
File Descriptor 63 kshkid Programming 3 03-02-2006 11:41 AM
apt-file returns nothing; 'bad file descriptor' overbored Debian 3 10-03-2004 09:13 PM
File descriptor lido Linux - Newbie 5 07-17-2003 11:58 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration