Sponsored Content
Top Forums Shell Programming and Scripting bash: closing file descriptors from a process Post 302452604 by jelloir on Sunday 12th of September 2010 04:12:21 AM
Old 09-12-2010
bash: closing file descriptors from a process

Below is a test script to illustrate a problem from a larger script I am writing.

Code:
$ cat /tmp/loggingtest 
#!/bin/bash

lvcreate -s -l 100%FREE -n var-data-snapshot vg00/var-data 2> >(logger -t "loggingtest.crit") 1> >(logger -t "loggingtest.info")

sync &
wait

lvremove -f vg00/var-data-snapshot 2> >(logger -t "loggingtest.crit") 1> >(logger -t "loggingtest.info")

When I run this I receive the following output in /var/log/syslog.
Specifically I cannot understand where the "File descriptor 62 left open" and "File descriptor 63 left open" errors are coming from. Also the script hangs until I press enter.

Code:
Sep 12 11:57:39 debvelopment loggingtest.crit: File descriptor 62 left open
Sep 12 11:57:39 debvelopment loggingtest.crit: File descriptor 63 left open
Sep 12 11:57:39 debvelopment loggingtest.info:   Logical volume "var-data-snapshot" created
Sep 12 11:57:39 debvelopment loggingtest.crit: File descriptor 62 left open
Sep 12 11:57:39 debvelopment loggingtest.crit: File descriptor 63 left open
Sep 12 11:57:39 debvelopment loggingtest.info:   Logical volume "var-data-snapshot" successfully removed

I have done research but I am finding it difficult to understand whether these errors are related to lvm, syslog or something I am doing wrong in bash? let alone how to close the file descriptors properly.

---------- Post updated at 06:12 PM ---------- Previous update was at 12:01 PM ----------

I can now prevent the errors and know that the descriptors are from "logger" but I still do not understand it.

I added "62>&- 63>&-" to the end of each command and this resolves the errors e.g.

Code:
#!/bin/bash

lvcreate -s -l 100%FREE -n var-data-snapshot vg00/var-data 2> >(logger -t "loggingtest.crit") 1> >(logger -t "loggingtest.info") 62>&- 63>&-

sync &
wait

lvremove -f vg00/var-data-snapshot 2> >(logger -t "loggingtest.crit") 1> >(logger -t "loggingtest.info") 62>&- 63>&-

But what if the file descriptors where to change? How can I identify the relevant file descriptors and then close them? Do I need to even be concerned as they appear to close anyway?

Thanks
 

10 More Discussions You Might Find Interesting

1. Programming

File Descriptors

Hi, I have written a daemon process, to perform certain operations in the background. For this I have to close, the open file descriptors, Does anybody know how to find out the number of open file descriptors ? Thanks in Advance, Sheetal (2 Replies)
Discussion started by: s_chordia
2 Replies

2. UNIX for Advanced & Expert Users

File Descriptors

Hello all, A few questions on file descriptors ... scenario : Sun Ultra 30 with Sun OS 5.5.1 , E250 with Solaris 2.6 In one of my servers, the file descriptor status from the soft limit and hard limits are 64 and 1024 respectively for root user. Is the soft limit (64) represents the... (3 Replies)
Discussion started by: shibz
3 Replies

3. UNIX for Dummies Questions & Answers

file descriptors

i m trying to learn processes in unix and i've been reading this but i don't quite get it. its regarding file descriptors. : each is a part of file pointers, they point to another area. indexes into an Operating system maintained table called "file descriptor table". one table per process. may... (3 Replies)
Discussion started by: a25khan
3 Replies

4. UNIX for Advanced & Expert Users

Max No of Open File Descriptors in a process

I have set the maximum no of file descriptors open in a process to the value 8192 using the following lines set rlim_fd_max=8192 set rlim_fd_cur=8192 in the /etc/system file. I rebooted the machine and the command ulimit -n / -Hn both display the limits as 8192. However when I run my... (2 Replies)
Discussion started by: lakshmankumar12
2 Replies

5. UNIX for Advanced & Expert Users

how to run a process after closing the terminal

i want to execute a shell script even if the terminal is closed. how to do? (3 Replies)
Discussion started by: lakshmananindia
3 Replies

6. UNIX for Dummies Questions & Answers

Closing ssh when process run on remote

Hi! I currently run a very long script (two hour left...) on a remote computer through a ssh session. I wonder whats happend if I close the ssh session, or even, the terminal. Is the script running on remote will stop? Thanks for your answers, Tp (1 Reply)
Discussion started by: tipi
1 Replies

7. Shell Programming and Scripting

Bash script to process file without regard for case

Hello, I have a Bash script that processes a text file so that the existing file will look something like this: /www/repository/2010/201002231329532/LTLO_0407.pdf /www/repository/2010/201002231329532/LTLO_0507.pdf /www/repository/2010/201002231329532/LTLO_0607.pdf... (1 Reply)
Discussion started by: manouche
1 Replies

8. Shell Programming and Scripting

Closing open file descriptors from /proc/pid/fd

Hi guys, i need to write a shell script that will close file descriptors from /proc/pid/fd will calling exec 4<&- solve the problem ? thanks in advance :) (15 Replies)
Discussion started by: alpha_romeo
15 Replies

9. Emergency UNIX and Linux Support

Nohup process getting killed after closing PUTTY session

I am running a process in nohup . nohup getkeys.ksh 132 > 132.out & When I close the putty terminal,The process is getting killed . default_signal_handler called for signal no: 1 Is there a way to keep the process running even If I close the terminal (2 Replies)
Discussion started by: prasperl
2 Replies

10. Shell Programming and Scripting

File descriptors -- cygwyn bash (windows)

Cygwin bash script was invoked in bash shell as follows: /cygdrive/c/cygwin/bin/bash test.sh This is content of my script #!/bin/bash # exec 3</cygdrive/c/cygwin/home/work/part1.txt read -u 3 x echo $x exec 3<&- Commands work correctly when issued one at a time within bash shell.... (2 Replies)
Discussion started by: joed270
2 Replies
LOGGER(1)						    BSD General Commands Manual 						 LOGGER(1)

NAME
logger -- a shell command interface to the syslog(3) system log module SYNOPSIS
logger [-isd] [-f file] [-p pri] [-t tag] [-u socket] [message ...] DESCRIPTION
Logger makes entries in the system log. It provides a shell command interface to the syslog(3) system log module. Options: -i Log the process id of the logger process with each line. -s Log the message to standard error, as well as the system log. -f file Log the specified file. -p pri Enter the message with the specified priority. The priority may be specified numerically or as a ``facility.level'' pair. For example, ``-p local3.info'' logs the message(s) as informational level in the local3 facility. The default is ``user.notice.'' -t tag Mark every line in the log with the specified tag. -u sock Write to socket as specified with socket instead of builtin syslog routines. -d Use a datagram instead of a stream connection to this socket. -- End the argument list. This is to allow the message to start with a hyphen (-). message Write the message to log; if not specified, and the -f flag is not provided, standard input is logged. The logger utility exits 0 on success, and >0 if an error occurs. Valid facility names are: auth, authpriv (for security information of a sensitive nature), cron, daemon, ftp, kern (can't be generated from user process), lpr, mail, news, security (deprecated synonym for auth), syslog, user, uucp, and local0 to local7, inclusive. Valid level names are): alert, crit, debug, emerg, err, error (deprecated synonym for err), info, notice, panic (deprecated synonym for emerg), warning, warn (deprecated synonym for warning). For the priority order and intended purposes of these levels, see syslog(3). EXAMPLES
logger System rebooted logger -p local0.notice -t HOSTIDM -f /dev/idmc SEE ALSO
syslog(3), syslogd(8) STANDARDS
The logger command is expected to be IEEE Std 1003.2 (``POSIX.2'') compatible. AVAILABILITY
The logger command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/. 4.3 Berkeley Distribution June 6, 1993 4.3 Berkeley Distribution
All times are GMT -4. The time now is 11:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy