Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have several launchers on my desktop for various programs, and there is a "run in a terminal" setting for those launchers.

When I check that setting, the program runs from a terminal, and logs its output there. I suppose that it could read stdin from the terminal too.

However: what happens to IO when the program is not ran by a terminal? Also, what happens when I execute system (shell) commands from a program like that?

Is there a "background" shell that runs those programs? Or does every program get its shell through which it interfaces with the rest of the system?

share|improve this question
    
I believe each output stream (STDOUT, STDERR) has a default location to go to if it hasn't been manually redirected by the user. I would imagine that if output was being generated but not user terminal was present to capture it, it would be redirected to /dev/null. I could be wrong though. –  maxmackie Mar 1 '13 at 11:36

1 Answer 1

up vote 2 down vote accepted

When a program is launched (by one of the exec(3) family of system calls), it inherits the environment (i.e., shell variables exported) and the open files from the parent. What is done when launching a program is a fork(2), the child sets up the environment and files, then exec(3)s the new program. When a shell does this, STDIN, STDOUT and STDERR are connected to the terminal. What any graphic launcher does is up to it, but is should connect them to /dev/null (where should keyboard input come from, and where should output go to?).

If a program launched like that in turn calls exec(3), it is as explained above. system(3) is a bit more complex, as it spawns a shell to do command line parsing and so on, and that shell then exec(3)s the command. But the mechanics is the same: Files are inherited, as is the environment.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.