Is this a legal close-on-exec-move?


 
Thread Tools Search this Thread
Top Forums Programming Is this a legal close-on-exec-move?
# 8  
Old 07-08-2007
Quote:
Originally Posted by frequency8
I could have sworn to god that I read someone that fork and exec created new fd's in the book "Advanced Programming in the Unix Environment" by Stevens and Rago.
Okay, it does not "create new file descriptors", it duplicates the parents file descriptors in the new child's process table, just like it copies the memory image.

A single process has no new file descriptors added to it's table as a result of calling fork or exec.
# 9  
Old 07-08-2007
Quote:
Originally Posted by porter
Okay, it does not "create new file descriptors", it duplicates the parents file descriptors in the new child's process table, just like it copies the memory image.

A single process has no new file descriptors added to it's table as a result of calling fork or exec.
I think the original poster is concerned with the quantity of file descriptors open, so these difference in replies are semantic in nature - or at least that is how is appears to me.

If you "duplicate" file descriptors, someone might also say that new file descriptors are "created" because the number of file descriptors increases.
# 10  
Old 07-08-2007
Well, but if a process is running out of fd's, it will never be due to the use of fork(). fork() creates a new process and the new process has its own set of newly created fd's. But the number of fd's in the original process does not grow. And while exec() can indeed close a fd if the close-on-exec bit was set, exec() does not have an "open-on-exec" concept. On the other hand, those dup2() do not look right. And dup2() can indeed add an fd to a process. We do not see how STDIN_FILENO and STDOUT_FILENO are defined so we can't be sure of what is happening. The return code from dup2 is being discarded so we don't know if the calls worked or not. I'm worried that this code might effectively be:
dup2(0,0);
dup2(1,1);
And it's not real clear what that would do. In a call like dup2(first, second), the man page says that since the second fd is open, it must be closed first. Smilie Or despite being all-caps, STDIN_FILENO and STDOUT_FILENO might actually be variables that get incremented somewhere. Also nowhere do I see anything about close-on-exec in the code... I don't understand why close-on-exec is even being mentioned here.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Programming

Array[count+1] legal?

I get weird decimal digits when I run the program below. int coe_amount; cout << "How many coefficients exist in your term? "; cin >> coe_amount; float coefficient; for (int count = 0; count < coe_amount; count ++) { ... (4 Replies)
Discussion started by: DyslexicChciken
4 Replies

2. Shell Programming and Scripting

Find and move command with exec

Hi all, I am trying to find files newer than a given file and them mv them to a new location. So I far I have: find . ! -newer <file_name> -exec ls -l {} \; and find . ! -newer <file_name> -exec mv /TEMP_LOCATION {} \; find is not liking this. Anyone know how to modify the last... (2 Replies)
Discussion started by: jonnyd
2 Replies

3. Shell Programming and Scripting

Script Variables Inquiry, Values Okay in Standalone Exec, No-Show in Cron Exec

I have the following bash script lines in a file named test.sh. #!/bin/bash # # Write Date to cron.log # echo "Begin SSI Load $(date +%d%b%y_%T)" # # Get the latest rates file for processing. # d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1) filename=$d export filename... (3 Replies)
Discussion started by: ginowms
3 Replies

4. Programming

when parent process close, how to close the child?

can someone provide an example, where if the parent process quits for any reason, then the child process will also close? (3 Replies)
Discussion started by: omega666
3 Replies

5. AIX

Legal Disclaimer setup in CDE

Hi pals I manage nearly 200+ aix workstations. I need to setup a legal disclaimer in all the workstations. When the user do a interactive login in CDE the legal disclaimer should be displayed and once he accepts the same he should be able to login to system. Can anybody suggest me as to... (0 Replies)
Discussion started by: sriram.s
0 Replies

6. Programming

legal code?

hi friends, the following code works fine,but the question is "is this a valid c". i really have no idea....... void func() { int x = 50; { int y; y = x + 400; printf("x = %d\n",x); printf("y = %d\n",y); } } (2 Replies)
Discussion started by: mxms755
2 Replies

7. Shell Programming and Scripting

Not Legal Characters

I have a file that I want to grep and identify all of the illegal characters. I have a list of legal ascii characters \11\12\40-\176,\0-\255 so i try a grep -v to exclude these but my syntax is not correct?? $ cat TRANS_20050613_00.DAT.ERROR | grep -v '\11\12\40-\176\0-\255' grep:... (2 Replies)
Discussion started by: lesstjm
2 Replies
Login or Register to Ask a Question