First of all, let me warn you I'm quite new to the world of LINUX and Operating Systems understanding, so that's why I pose these newbie and stupid qustions...
Anyway, I'm trying to build my own simple shell in C and I'm getting some problems in implementing the background process ('&') functionality.
The parsing of the input command is taken care of, the thing is, when forking a new process after a previous forking of a background process, the new child process shows a parent PID as the PID of that background process and not the PID of the shell process...
I think the problem resides in the fact that i actually DON'T KNOW what a background process really is... I just tell a background process from a 'normal' one by not calling/ calling the wait() system call:
I also get some problems with the exit() system call... When I call it, the process that is terminated is the one of the shell!
Can you help me with something here?
Thanks!
Damiao
Last edited by Perderabo; 02-08-2008 at 01:38 PM..
Reason: Switch quote tags to code tags
First of all, let me warn you I'm quite new to the world of LINUX and Operating Systems understanding, so that's why I pose these newbie and stupid qustions...
Looks to me you're doing quite fine...
Quote:
The parsing of the input command is taken care of, the thing is, when forking a new process after a previous forking of a background process, the new child process shows a parent PID as the PID of that background process and not the PID of the shell process...
I don't see how that's happening in the code below. But there is a bug...
Quote:
I think the problem resides in the fact that i actually DON'T KNOW what a background process really is... I just tell a background process from a 'normal' one by not calling/ calling the wait() system call:
Pretty much you have it right. The confusion may be what fork() does. fork() clones the process; the new process has a pid of 0. You do not (normally) want to exit() after a fork() call. The exception is when exec() fails in the new process.
There are also some other considerations in creating a background process. Which process will have control of the terminal? Where will the background process receive "stdin" from? Normally, you should close stdin (fd[0]) before spawning the background process.
Hi,I am also having problems in background processes for my shell...
how do i set the control terminal of my bg process?do i need to use the signals SIGTTIN and SIGTTOU?
Your question was a bit vague, so forgive me if this does not answer your question.
Usually, the background process does not (not should not) have a controlling TTY. If it does, it is because the parent process did not close all TTY-open file descriptors (such as stderr and stdin) after the fork() and before the exec().
ok...i am developing a new shell ..just for fun and learning...
how do i disconnect my bg process from tty...?
Currently i just fork and execl the child and parent doesn't wait.
On receiving sigcld,i print that child is done...but is there any way to see the exit status?
and abt the controlling termnal...i want to know how to connect nd disconnect and also how to interact with a control terminal from background...pls throw some light...
After the fork(), in the child process, close your file descriptors, then do the exec. In the parent process, I believe you can call waitpid() inside the signal handler. You should be able to get the status there.
As to how to "connect/disconnect" or "interact" with a control terminal from the background? (like the 'fg/bg' commands) That I don't know.
You know, you could aways download bash or zsh and analyze the source code... maybe strip the code until you see how they do it. Or would that be cheating?
How do I list the process in a Unix based system which are running in background?
The following are options that I'm aware of, but they may not be appropiate.
a. using ps -ef , and getting records of processes for which STATUS='S'(uninterruptible sleep)
b. using jobs -l, and filtering... (5 Replies)
Hi,
I have a schell script parent.ksh from which I am calling three background processes a.ksh,b.ksh and c.ksh. Once these three processes completes the next step in parent.ksh should execute. How to achieve this?
Please help me....
Thanks... (1 Reply)
Ok guys so I have my first dummy shell almost done except for one tiny part: I do not know how to run a process in the background, from the code!
I already know how to do that in a normal shell:
$ program &
However, no clue when it comes to how to program that thing. :eek:
A very... (2 Replies)
Hi,
I need to establish a procedure that will start an application in background each time my remote Solaris server is (re)started. This would be a kind of daemon. I am no sysadmin expert, so I am looking for pointers.
How should I proceed? What are the main steps?
Thanks,
JVerstry (9 Replies)
Hi,
Inorder to improve the performance, I am trying to execute my command as a background process..
For eg: To zip large numbers of files present in a directory instead of using a single process, i do follow the below method:
gunzip -c > / &... (3 Replies)
I've got a bit of code I'm trying to work on...
What i want to happen is ... at all times have four parallel mysql dump and imports running.
I found the follow code snippet on the forum and modified it to work
by starting four concurrent processes but it waits until all four are done before... (7 Replies)
I have installed oracle 10g on suse sles9. I do not see oracle background processes.
ps -ef|grep ora_ gives me environment variables junk.
ps -ef|grep smon does not show anything however database is up and running.
Any idea how to tweak that? (1 Reply)
Hey guys,
I am writing a very simple dummy shell in C++ and I am having trouble getting a process to run in the background. First of all, the shell has to recognize when I input a "&" at the end of the command, then it has to stick it in the background of the shell.
I understand that if I want... (6 Replies)
hi there,
here's what i need in my korn-shell:
... begin korn-shell script
... nohup process_A.ksh ; nohup process_B.ksh &
... "other stuff"
... end lorn-shell script
in plain english i want process A and process B to run in the background so that the script can continue doing... (6 Replies)
How do you capture the return code from a background process?
I am dumping data to a fifo and then processing it in a c program.
I need to know that the sql finished successfully to ensure no missing data. Thanks.
ex.
sqlplus user/password < get_data.sql > data_fifo.txt &
bin/process_data... (2 Replies)