473,785 Members | 2,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Release file descriptor in c/c++

I have a c/c++ program in linux.

I would like to know if I kill my program (e.g. exit(1)), will it
release all the file descriptors my program held (regardless if I call
close(fd) of each file descriptor)?

Thank you.

Oct 8 '07 #1
5 5264
On Oct 8, 6:33 am, "ying...@gmail. com" <ying...@gmail. comwrote:
I have a c/c++ program in linux.

I would like to know if I kill my program (e.g. exit(1)), will it
release all the file descriptors my program held (regardless if I call
close(fd) of each file descriptor)?

Thank you.
Someone could correct me if I'm wrong, but a guarantee that the
standard does make is that functions registered with atexit will
get called following the call to exit. This implies that you
could bind files to objects with static storage if you want
to ensure they get closed.

Regards,

Werner

Oct 8 '07 #2
On 2007-10-08 15:14, werasm wrote:
On Oct 8, 6:33 am, "ying...@gmail. com" <ying...@gmail. comwrote:
>I have a c/c++ program in linux.

I would like to know if I kill my program (e.g. exit(1)), will it
release all the file descriptors my program held (regardless if I call
close(fd) of each file descriptor)?

Thank you.

Someone could correct me if I'm wrong, but a guarantee that the
standard does make is that functions registered with atexit will
get called following the call to exit. This implies that you
could bind files to objects with static storage if you want
to ensure they get closed.
That should work, but it will not help if abort() is called. On the
other hand, most modern OSes will release file-handles and other
resources associated with a process when it terminates (however it might
or might not flush any buffered data).

--
Erik Wikström
Oct 8 '07 #3
On 2007-10-07 20:04:47 -1000, "Alf P. Steinbach" <al***@start.no said:
* yi*****@gmail.c om:
>I have a c/c++ program in linux.

I would like to know if I kill my program (e.g. exit(1)), will it
release all the file descriptors my program held (regardless if I call
close(fd) of each file descriptor)?

"File descriptor" is not defined by, or even mentioned in, the C++ standard.

However, possibly you mean "will all open files be closed".

And the answer is that the C++ standard only makes a guarantee in the
opposite direction, what will /not/ happen, namely that exit() will not
call destructors of local objects.
Gosh, are all those words in [support.start.t erm]/8 that seem to be
talking about what exit() does just spares?

In both C and C++, among other things, exit() flushes buffers and
closes all C streams.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Oct 8 '07 #4
On 2007-10-08 08:57:51 -1000, "Alf P. Steinbach" <al***@start.no said:
* Pete Becker:
>On 2007-10-07 20:04:47 -1000, "Alf P. Steinbach" <al***@start.no said:
>>* yi*****@gmail.c om:
I have a c/c++ program in linux.

I would like to know if I kill my program (e.g. exit(1)), will it
release all the file descriptors my program held (regardless if I call
close(fd) of each file descriptor)?

"File descriptor" is not defined by, or even mentioned in, the C++ standard.

However, possibly you mean "will all open files be closed".

And the answer is that the C++ standard only makes a guarantee in the
opposite direction, what will /not/ happen, namely that exit() will not
call destructors of local objects.

Gosh, are all those words in [support.start.t erm]/8 that seem to be
talking about what exit() does just spares?

No, the standard just doesn't mention "file descriptors", nor "close(fd)" .
Sigh. I knew you'd pretend you said something different from what you
actually said, which is all still quoted above.
>
>In both C and C++, among other things, exit() flushes buffers and
closes all C streams.

close(fd), mentioned by the OP, is not an operation on a C stream.
I.e., the flushing and closing of C streams is generally irrelevant to
the OP's "file descriptors", except that it may close those "file
descriptors" that correspond to C streams (but there is no guarantee
that a C stream is implemented in terms of a "file descriptor").
Indeed. What I said is, nevertheless, true, and what you said is not.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Oct 8 '07 #5
On 2007-10-08 10:11:40 -1000, "Alf P. Steinbach" <al***@start.no said:
* Pete Becker:
>On 2007-10-08 08:57:51 -1000, "Alf P. Steinbach" <al***@start.no said:
>>* Pete Becker:
On 2007-10-07 20:04:47 -1000, "Alf P. Steinbach" <al***@start.no said:

* yi*****@gmail.c om:
>I have a c/c++ program in linux.
>>
>I would like to know if I kill my program (e.g. exit(1)), will it
>release all the file descriptors my program held (regardless if I call
>close(fd ) of each file descriptor)?
>
"File descriptor" is not defined by, or even mentioned in, the C++ standard.
>
However, possibly you mean "will all open files be closed".
>
And the answer is that the C++ standard only makes a guarantee in the
opposite direction, what will /not/ happen, namely that exit() will not
call destructors of local objects.
>

Gosh, are all those words in [support.start.t erm]/8 that seem to be
talking about what exit() does just spares?

No, the standard just doesn't mention "file descriptors", nor "close(fd)" .

Sigh. I knew you'd pretend you said something different from what you
actually said, which is all still quoted above.

I think that when you read the text and ended up with some meaning that
didn't make sense, whatever it was, you knew that that interpretation
was silly.
What you said:

"However, possibly you mean 'will all open files be closed'."
"And the answer is that the C++ standard only makes a guarantee in the
opposite direction, what will /not/ happen, namely that exit() will not
call destructors of local objects.

The C++ standard guarantees that exit() flushes buffers and closes C
streams. That is more than a guarantee of what will not happen.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Oct 8 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6284
by: pembed2003 | last post by:
Hi all, Given something like: std::ofstream out_file("path"); how do I extract the file descriptor from out_file? Is it possible? What I want is to extract the file descriptor and then pass it to flock like: flock(???, LOCK_EX);
9
10904
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent the wheel, right? Everything so far is working well with the Active Directory. The problem I am having is with adding File Permissions to a directory. I am currently using some code courtesy of "Willy Denoyette "
2
5047
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified folder structure and naming conventions and then send a Net send message to those users telling them to rectify. The information I want to get is when you select the file/folder and then: Properties -> Security Tab -> Advanced Button -> Owner Tab ->...
2
3439
by: levimc | last post by:
I know that that topic may be old to you but I looked at other more- than-two-year-old topics related to mine. However, I didn't find them working for my project at all because its errors return back to me everytime. The error I have on that project said: "An unhandled exception of type 'System.EntryPointNotFoundException' occurred in TestSysaudit.exe
3
5273
by: Yang | last post by:
Hi, I'm experiencing a problem when trying to close the file descriptor for a socket, creating another socket, and then closing the file descriptor for that second socket. I can't tell if my issue is about Python or POSIX. In the following, the first time through, everything works. On the second connection, though, the same file descriptor as the first connection may be re-used, but for some reason, trying to do os.read/close on that...
0
6030
ashitpro
by: ashitpro | last post by:
As per the last discussion(chapter 1), here we'll try to read the group descriptor. First of all we'll try to understand what is group descriptor. AS we know, superblock and group descriptor table are duplicated in each block group. Group descriptor table is an array of group desciptors Each block group has it's own group descriptor. And it is stored in group discriptor table in sequential manner. In other word each block group has all...
3
6250
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store that multiple worksheet data in different table.How can i do it.Below is my xml file. <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" ...
3
5402
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store that multiple worksheet data in different table.How can i do it.Below is my xml file. <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office"...
9
9339
by: Bill David | last post by:
I know it's very strange to do that since we have the file name when we call: int open(const char *pathname, int oflag,...); And we can store the file name for later usage. But I just wonder if we can get a file name from the file descriptor (on Windows/Linux), then the solution may looks simpler (if it's not so hard to get the file name, :) ).
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10341
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8979
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.