Non-interactive & non-login shell environment?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Non-interactive & non-login shell environment?
# 1  
Old 11-16-2017
Non-interactive & non-login shell environment?

Hello and thanks in advance for any help anyone can offer to straighten me out on this subject

I'm trying to understand non-interactive & non-login shells and having a hard time conceptualize the process a non-interactive & non-login shell goes through to start up. Particularly for background processes.

The way I understand things is when a process is started.... a region of memory is created and the child process replicates a duplicate environment of the parent by being forked. What's confusing me is when is the shell environment defined for a background process? When I think about how an interactive shell is started I get a little lost.

The way I understand an interactive shell is:
  1. User passes login ID to Linux kernel
  2. Linux kernel looks the user up in the /etc/password file and identifies the assigned shell
  3. the shell is started
  4. the shell reads the login scripts to define the shell environment for the user
  5. Linux produces a command prompt to indicate the shell is ready to accept commands


Do processes that start in the background have a similar process it steps through? This is how I envision it working:
  1. The process is forked by the parent process
  2. Linux identifies the user ID the process will runs as
  3. Linux looks the user id up in the /etc/passwd file
  4. the shell is started
  5. the BASH_ENV is read (If it was defined)
  6. the process interacts with the shell to pass commands to the API

For example... An Oracle database would have the user ID of oracle and be assigned the /bin/bash shell... Would this process accurately describe what it goes through when it starts?

For some reason this seems clunky and like I'm missing something... Could someone let me know if I'm on the right path please?

Thank you very much!

Last edited by rbatte1; 11-17-2017 at 07:57 AM.. Reason: Formatted numbered lists with LIST=1 tags
# 2  
Old 11-16-2017
Quote:
The way I understand an interactive shell is:
1. User passes login ID to Linux kernel
What you forgot to mention is how does a user connect... and so he has a TTY( or whaterver...) defined and keyboard, StdIn and StdOut are set to those...

what do you expect a non interactive shell to use as INPUT and output?

What will the non-interactive shell do when in the user env it reads TERM=VT100 or export DISPLAY=....
etc...

Last edited by rbatte1; 11-17-2017 at 07:57 AM.. Reason: Adjusted quote to match my edit of initial post
# 3  
Old 11-16-2017
Thanks for the reply!

After giving things a bit of thought I'm mostly confused with background processes. In a hypothetical situation.... an Oracle database requires the user ID named oracle with the /bin/bash associated with it to run.

What I'm trying to figure out is when does a background process, like a database or web server, start the shell and read in any environment variables... and then does it use the shell to pass commands to the API.

If you could offer any insight to this I would be grateful!
# 4  
Old 11-16-2017
Good practices will be to never use oracle for anything else than owner of the product, you create dba users owners of the instance it will run and put the user in group dba ( otherwise how will you recognise the processes of different running instances if they all belong to oracle? ... but thats not the point here... When are the environment set? well before you initialise the instance, that means usually you would have a start/stop script that will either set all the needed env variables or source from the user's .profile if the .profile ( or .bashrc etc... ) is written properly, that means testing if the shell is interactive or not ( yes I have boxes with more than 10 instances running... )
# 5  
Old 11-16-2017
Thanks for the reply again... You sort of touched on the part of where I'm getting confused at. My understanding of a background process like a user ID for an Oracle database is it would be a non-interactive and non-login shell... From what I've read in the Bash man page a login script shouldn't run in a non-interactive shell
Quote:
When bash is started non-interactively, to run a shell script, for example, it looks for the variable BASH_ENV in the environment, expands its value if it appears there, and uses the expanded value as the name of a file to read and execute.
It specifies a script and not a process... Which makes me wonder how does a background process owned get the environment. Also, from what I've read a background process passes commands to the API... Which makes me confused as to where a shell comes into things in this sort of scenario

Once again... thanks for your replies and patience!
# 6  
Old 11-17-2017
The "Linux" kernel handles the scheduling/multitasking and all the I/O, and it knows what an UIDs/owner is.
But it does not know what a shell is, and does not know that a UID is stored in a passwd file.
Nevertheless the kernel handle many atomic operations. Its API towards userland is in man page section 2; in Linux you can list them with:
Code:
man -k . | grep '(2)'

The userland is all the processes. The shell is a normal process. A lot userland code is stored in shared libraries, so the processes simply load the libraries and stay small. The ps -ef command also lists some kernel threads and assignes the PID 0, while the real processes in userland have PID 1 and higher.

The criteria interactive/non-interactive and login/non-login is a matter of the shell, or of the process that invokes it. You can read more of it in the man page
Code:
man sh
man bash

The invocation of a new process is done via a couple of the kernel API functions, basically fork() and exec().
# 7  
Old 11-17-2017
Quote:
Originally Posted by bodisha
Thanks for the reply again... You sort of touched on the part of where I'm getting confused at. My understanding of a background process like a user ID for an Oracle database is it would be a non-interactive and non-login shell...
The shell is not actually in charge, it just helps arrange things. The shell isn't necessarily involved at all in creating the Oracle process, or creating any other process for that matter.

The one and only difference between "interactive" and "noninteractive" processes, as far as the kernel is concerned, is whether your process has a controlling terminal. The kernel knows what your terminal is even if your process doesn't - you can open it via /dev/tty. The kernel doesn't really care whether you have a terminal.

In the old days terminals were really terminals - physical devices attached to serial ports. /bin/login did the job of holding those ports open and reading username/passwords from them. Each port would have one /bin/login process running for it. These days, things like ssh have mostly taken over the job of sitting around and waiting for user input, terminals have become imaginary devices which get created and destroyed at need.

The login program creates your shell. It owns the terminal, and opens it, duplicating it onto file descriptors 0, 1, and 2 for you - standard input, standard output, and standard error. Then login runs your shell and lets it take over from there.

Quote:
It specifies a script and not a process... Which makes me wonder how does a background process owned get the environment.
When a process is created, it receives a copy of the environment of its parent. So it comes down to where the parent got its environment.

Last edited by Corona688; 11-17-2017 at 07:00 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