Sponsored Content
Full Discussion: terminal problem
Top Forums Programming terminal problem Post 302102696 by heck on Friday 12th of January 2007 07:48:02 AM
Old 01-12-2007
inherited file descriptors

i am not sure but, i could be the following reason:

Open descriptors are inherited to child process, this may cause the use of resources unneccessarily. Unneccesarry descriptors should be closed before fork() system call (so that they are not inherited) or close all open descriptors as soon as the child process starts running.
Code:
	for (i=getdtablesize();i>=0;--i) close(i); /* close all descriptors */

There are three standart I/O descriptors: standart input 'stdin' (0), standart output 'stdout' (1), standart error 'stderr' (2). A standard library routine may read or write to standart I/O and it may occur to a terminal or file. For safety, these descriptors should be opened and connectedthem to a harmless I/O device (such as /dev/null).

Code:
i=open("/dev/null",O_RDWR); /* open stdin */
	dup(i); /* stdout */
	dup(i); /* stderr */

As Unix assigns descriptors sequentially, fopen call will open stdin and dup calls will provide a copy for stdout and stderr.

Be aware that system() from <cstdlib> or <stdlib.h> is sth. like a wrapper for fork() and exec(). popen() too as far as is know.

But, try this.

I would be helpfull if we knew what you are executing and what output you have on the screen.
cheeers
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

terminal problem

Hi all While trying to upon a new window it is saying UNABLE TO GET PTY..what does this means how to solve it Thanks Prafulla (4 Replies)
Discussion started by: Prafulla
4 Replies

2. UNIX for Advanced & Expert Users

terminal type problem with cygwin on aix

hey, I use cygwin to connect to AIX 5.2 but when I open vi I get an error saying: ex: 0602-108 cygwin is not a recognized terminal type how can I fix that? I thought cygwin was tty vt100? (1 Reply)
Discussion started by: rein
1 Replies

3. SCO

Terminal Allocation Problem

Hello All, I am facing a problem on SCO Open Server V 5x, We are using serial communication on dumb terminals, right now i am facing a problem on some terminals, as they are not showing thier previous tty no, as tty13 or tty18, but they are showing ttya6 or ttya4, i also tried to move and link... (5 Replies)
Discussion started by: Awadhesh
5 Replies

4. Linux

tty terminal permissions problem

I'm hoping someone can help me out here. I'm having a problem on my Red Hat Enterprise 5 Server where my tty devices "tty" are being set to read only permissions. I need them to be set to 777 in order to write to the serial printers through a custome application. I have gone through many... (2 Replies)
Discussion started by: Netwrkengeer
2 Replies

5. Shell Programming and Scripting

Problem with gnome-terminal

Hello everyone. This is my first post.:o Using Ubuntu 8.04 and bash 3.2.39 i'm trying to adapt my routine to this platform. So, this means forget xterm and use gnome-terminal (as default ubuntu terminal). EveryDay i need to connect to several servers, and i've made a Tcl'script to make this... (1 Reply)
Discussion started by: trutoman
1 Replies

6. Shell Programming and Scripting

Problem - gnome terminal shell scripting

I've a python script named rwe.py. I'm running the program in three separate terminals. If one of the executing program stops . I want to leave the terminal as it is so that i can see the error. i wrote a the below script and used cron to run it every one hour to check if the three programs are... (0 Replies)
Discussion started by: msteve2002
0 Replies

7. Linux

Terminal logging character problem -Newbie-

Im a complete newbie tryin to work with linux centos; in terminal wanted to log with script command; but output file has some strange characters when I try to open with gedit or bluefish terminal , gedit, bluefish encoding is utf-8 ; Script started on Mon 08 Mar 2010 03:32:39 PM EET... (2 Replies)
Discussion started by: anacondauser
2 Replies

8. HP-UX

Problem with terminal

Hi Guys, I'm using my putty to connect to the HP-UX test box. Once I get connected to server there seem to be something wrong with my putty that behaves very odd. for example it starts from the half of the screen. I really dont know how to explain this problem. or for instance when i run vi to... (2 Replies)
Discussion started by: messi777
2 Replies

9. UNIX for Dummies Questions & Answers

sed Or Grep Problem OR Terminal Problem?

I don't know if you guys get this problem sometimes at Terminal but I had been having this problem since yesterday :( Maybe I overdid the Terminal. Even the codes that used to work doesn't work anymore. Here is what 's happening: * I wanted to remove lines containing digits so I used this... (25 Replies)
Discussion started by: Nexeu
25 Replies

10. Shell Programming and Scripting

Problem reading terminal response string from Zsh

Note: This posting is related to my posting at bash - Reading answer to control string sent to xterm - Stack Overflow , but I could get there a solution only for bash. I can use that solution, but for curiosity, I wonder, whether I could do this in Zsh as well. The problem is to send a (Posix-)... (6 Replies)
Discussion started by: rovf
6 Replies
DUP(2)							     Linux Programmer's Manual							    DUP(2)

NAME
dup, dup2 - duplicate a file descriptor SYNOPSIS
#include <unistd.h> int dup(int oldfd); int dup2(int oldfd, int newfd); DESCRIPTION
dup and dup2 create a copy of the file descriptor oldfd. After successful return of dup or dup2, the old and new descriptors may be used interchangeably. They share locks, file position pointers and flags; for example, if the file position is modified by using lseek on one of the descriptors, the position is also changed for the other. The two descriptors do not share the close-on-exec flag, however. dup uses the lowest-numbered unused descriptor for the new descriptor. dup2 makes newfd be the copy of oldfd, closing newfd first if necessary. RETURN VALUE
dup and dup2 return the new descriptor, or -1 if an error occurred (in which case, errno is set appropriately). ERRORS
EBADF oldfd isn't an open file descriptor, or newfd is out of the allowed range for file descriptors. EMFILE The process already has the maximum number of file descriptors open and tried to open a new one. WARNING
The error returned by dup2 is different to that returned by fcntl(..., F_DUPFD, ...) when newfd is out of range. On some systems dup2 also sometimes returns EINVAL like F_DUPFD. CONFORMING TO
SVr4, SVID, POSIX, X/OPEN, BSD 4.3. SVr4 documents additional EINTR and ENOLINK error conditions. POSIX.1 adds EINTR. SEE ALSO
fcntl(2), open(2), close(2) Linux 1.1.46 1994-08-21 DUP(2)
All times are GMT -4. The time now is 10:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy