Non-interactive & non-login shell environment?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Non-interactive & non-login shell environment?
# 8  
Old 11-17-2017
OK, so, to understand the difference between background and foreground processes, and where system services get their environment, I must explain how almost everything works from the ground up... Wish me luck.

For starters, the "environment". Every process has a block of memory devoted to storing text variables. These are not shell variables: They are used by programs but not actually a part of them. Any process can get to these variables, shells, editors, anything. A large part of the shell's job is setting up these variables for everything else.

UNIX creates processes by cloning your own process then replacing it with something else. The environment is part of the memory which gets cloned. So to run nano, your shell calls fork to clone itself, then the clone calls exec to replace itself with a text editor. The environment isn't touched by this replacement -- nano still has a perfect copy of your shell's environment after it loads.

To clone a process, one must first have a process, so when a UNIX kernel starts, it runs the program init as the very first process. It has no controlling terminal (or gets rid of its controlling terminal shortly after starting - either way.) init will stay running for as long as your system does.

There's only a few things run by init: It will run a copy of getty on each physical terminal to provide "Username:" login prompts on them, and it will run "rc" to start system services. Unlike init, rc does not stay running, it just starts processes then quits.

rc runs shell scripts to start system services, traditionally found in /etc/rc.d/ or /etc/init.d/, called "init scripts". It loads /etc/profile first before loading an init script to start a system service.

So the point to my really longwinded answer is that the rc program (or whatever equivalent your system has) is responsible for running everything that's not a terminal login, and therefore controls their environments. Its own environment is probably next to nothing. If you really need a custom environment for a service, its the job of its init script to set it up. (though many UNIX and Linux distributions now have set up a better place for it in /etc/conf.d/ which is more or less a per-service /etc/profile kind of thing. rc is responsible for loading it.)

Now, foreground and background processes. These are meaningless terms without a terminal, because all "foreground" means is "in control of the terminal". When you run nano, your shell hands control of the terminal to it, and when nano quits, it gets that control back.

Last edited by Corona688; 11-17-2017 at 08:34 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

How to set a non-login non-interactive shell for a user?

I am sorry for creating a new topic after my previous inquiry was closed, but I tried and tried and I do not know how to edit my previous post. This is not exactly any homework, this is one of 40 questions we were expected to prepare for one of the labs. I searched and read what I could and still... (4 Replies)
Discussion started by: me_me_me
4 Replies

2. UNIX for Advanced & Expert Users

Can adding to a new group be effective in current login environment without re-login?

Hey folks, When a user is added to a new group, the user has to be log out and log in again to make the new group effective. Is there any system command or technique to refresh user group ID update without re-login? I am not talking about to use "login" or "su -l" commands which can only make... (2 Replies)
Discussion started by: hce
2 Replies

3. Shell Programming and Scripting

Script as login shell (passing args to login shell)

Hello all, for security reasons my compagny imposes that my script be launch remotly via ssh under the users login shell. So serverA launches the ssh command to serverB which has a local user with my script as a login shell. Local script works like a charm on his own. serverB$ grep... (20 Replies)
Discussion started by: maverick72
20 Replies

4. Red Hat

Su-only account with ssh capability and no interactive login

Hello experts, Is it possible to have an user account on RHEL 6.3 as a su-only account, but with ssh capability and no interactive login? Let me elaborate. Say, we have a cluster of 5 RHEL 6.3 servers and an user account (strmadmin) on each of the server as an su-only... (1 Reply)
Discussion started by: naveendronavall
1 Replies

5. Programming

Non-interactive login using C program in UNIX(Solaris)

Hi i need a c programm to login in unix(solaris). non-interactivley because it seems difficult to do it with unix shell scripting and passwd command cant be used and also i don't have expect installed and i am not allowed to installed expect in our servers. is there any c programm that can help... (1 Reply)
Discussion started by: munish259272
1 Replies

6. UNIX for Dummies Questions & Answers

What is login and interactive shell?

Hi Guys, Excuse if am asking silly Que ... :rolleyes: Please explain me whats difference between login and interactive shell in Linux .. Have googled but still in doubt .. :confused: --Shirish Shukla (4 Replies)
Discussion started by: Shirishlnx
4 Replies

7. UNIX for Dummies Questions & Answers

Can't login to a free shell environment

I would like to practice shell scripting and need an environment - free shell account. I tried Arbornet and the freeshell.org. But both always give me error: "File operations disabled, server identity can't be verified". Any idea what I should do? thanks in advance. (9 Replies)
Discussion started by: laiko
9 Replies

8. Homework & Coursework Questions

Help with Interactive / Non Interactive Shell script

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (1 Reply)
Discussion started by: rits
1 Replies

9. Shell Programming and Scripting

how to write a shell script to login to a system which is interactive.

Can anybody help me to write a shell script to login interactive system once u open a connection using telnet it will ask for USERCODE: PASSWORD: DOMAIN: (1 Reply)
Discussion started by: sudhakaryadav
1 Replies

10. Shell Programming and Scripting

How to get environment of a "fresh" login shell?

Hello fellow *nix users! I am a bit confused how could I get an environment of a "fresh/clean" login shell, that is, the environment at that moment when user has started e.g. a new terminal/console or so. So this is the sequence of actions I should be able to do in a single shell session: ... (6 Replies)
Discussion started by: Miikka
6 Replies
Login or Register to Ask a Question