LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-13-2009, 05:44 PM   #1
alirezan1
Member
 
Registered: Nov 2004
Location: Vancouver
Distribution: Ubunty, CentOS ,Mandriva, Gentoo, RedHat, Fedora, Knoppix
Posts: 150

Rep: Reputation: 15
Starting Bash from a process


Hi

I want to do something that might sound strange.

I have a code that in written in C and is executed at startup (it's a custom process). It occasionally calls some bash scripts.

The process doesn't have any terminal associated with it.
One thing I don't know how to do is to start a bash session as a child to another bash session. Here's an example:

$ ps au
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2379 0.0 0.0 3360 1624 ttyS0 Ss 16:11 0:00 -bash
root 2691 0.0 0.0 2876 988 ttyS0 R+ 16:37 0:00 ps au


I have a bash session already running with PID 2379 and say I want to start a bash session as a child to that session so that I could actually see it in "ps au" output. But this session should be started by the process.

Anybody any ideas how I can do this?

Thanks
 
Old 03-13-2009, 05:55 PM   #2
rysiekmus2
Member
 
Registered: Mar 2007
Location: Manchester UK
Distribution: Sabayon
Posts: 30

Rep: Reputation: 17
bash session

Hi,

if you have a bash session, so for example you have the Linux console open and you type in "bash", that's exactly what happens, your new "bash" is a child proces to the bash you have in your Linux session.

Am I right?

Code:
rysiek@localhost ~ $ bash
rysiek@localhost ~ $ ps -f
UID        PID  PPID  C STIME TTY          TIME CMD
rysiek   11092 11091  0 21:52 pts/1    00:00:00 /bin/bash
rysiek   11096 11092  1 21:52 pts/1    00:00:00 bash
rysiek   11100 11096  0 21:52 pts/1    00:00:00 ps -f
The /bin/bash is the system called when I click on the Linux Console icon, the second bash is the child of the first one.

Richard
 
Old 03-13-2009, 06:03 PM   #3
alirezan1
Member
 
Registered: Nov 2004
Location: Vancouver
Distribution: Ubunty, CentOS ,Mandriva, Gentoo, RedHat, Fedora, Knoppix
Posts: 150

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by rysiekmus2 View Post
Hi,

if you have a bash session, so for example you have the Linux console open and you type in "bash", that's exactly what happens, your new "bash" is a child proces to the bash you have in your Linux session.

Am I right?

Code:
rysiek@localhost ~ $ bash
rysiek@localhost ~ $ ps -f
UID        PID  PPID  C STIME TTY          TIME CMD
rysiek   11092 11091  0 21:52 pts/1    00:00:00 /bin/bash
rysiek   11096 11092  1 21:52 pts/1    00:00:00 bash
rysiek   11100 11096  0 21:52 pts/1    00:00:00 ps -f
The /bin/bash is the system called when I click on the Linux Console icon, the second bash is the child of the first one.

Richard
yeah, but maybe I didn't explain correctly.

Say I have a process called "PROC" and my bash session (say PID=1234) is also running and have a local user logged in.
I want to start a bash session as a child to bash with PID of 1234 from the PROC process. So, the process automatically starts a bash shell on behalf of the process with PID 1234. if the PROC calls /bin/bash directly, the bash processes created would be the child to PROC.

Thanks
 
Old 03-14-2009, 12:58 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
You can't do that ie a child process is exactly that, has to be started from its parent. You can't create a child process on behalf of another process. Think of the security issues.
Maybe you could explain a bit more about what you are trying to achieve?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Starting process on display :1 noware Linux - General 8 12-01-2005 07:52 AM
a questions about starting process fetsh Linux - Newbie 2 06-03-2005 08:42 PM
Starting a program with a given process id DropSig Linux - Newbie 1 09-29-2004 09:41 PM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 02:19 PM
Starting anther process rklosinski Programming 5 12-05-2002 09:09 AM


All times are GMT -5. The time now is 04:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration