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
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)
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)
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)
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)
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)
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)
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)
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 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)
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)
Discussion started by: kumarjt
5 Replies
LEARN ABOUT XFREE86
wait
wait(1) User Commands wait(1)NAME
wait - await process completion
SYNOPSIS
/bin/sh
wait [pid...]
/bin/jsh /bin/ksh /usr/xpg4/bin/sh
wait [pid...]
wait [ % jobid...]
/bin/csh
wait
DESCRIPTION
The shell itself executes wait, without creating a new process. If you get the error message cannot fork,too many processes, try using the
wait command to clean up your background processes. If this doesn't help, the system process table is probably full or you have too many
active foreground processes. There is a limit to the number of process IDs associated with your login, and to the number the system can
keep track of.
Not all the processes of a pipeline with three or more stages are children of the shell, and thus cannot be waited for.
/bin/sh, /bin/jsh
Wait for your background process whose process ID is pid and report its termination status. If pid is omitted, all your shell's currently
active background processes are waited for and the return code will be 0. The wait utility accepts a job identifier, when Job Control is
enabled (jsh), and the argument, jobid, is preceded by a percent sign (%).
If pid is not an active process ID, the wait utility will return immediately and the return code will be 0.
csh
Wait for your background processes.
ksh
When an asynchronous list is started by the shell, the process ID of the last command in each element of the asynchronous list becomes
known in the current shell execution environment.
If the wait utility is invoked with no operands, it will wait until all process IDs known to the invoking shell have terminated and exit
with an exit status of 0.
If one or more pid or jobid operands are specified that represent known process IDs (or jobids), the wait utility will wait until all of
them have terminated. If one or more pid or jobid operands are specified that represent unknown process IDs (or jobids), wait will treat
them as if they were known process IDs (or jobids) that exited with exit status 127. The exit status returned by the wait utility will be
the exit status of the process requested by the last pid or jobid operand.
The known process IDs are applicable only for invocations of wait in the current shell execution environment.
OPERANDS
The following operands are supported:
One of the following:
pid The unsigned decimal integer process ID of a command, for which the utility is to wait for the termination.
jobid A job control job ID that identifies a background process group to be waited for. The job control job ID notation is applicable
only for invocations of wait in the current shell execution environment, and only on systems supporting the job control option.
USAGE
On most implementations, wait is a shell built-in. If it is called in a subshell or separate utility execution environment, such as one of
the following,
(wait)
nohup wait ...
find . -exec wait ... ;
it will return immediately because there will be no known process IDs to wait for in those environments.
EXAMPLES
Example 1: Using A Script To Identify The Termination Signal
Although the exact value used when a process is terminated by a signal is unspecified, if it is known that a signal terminated a process, a
script can still reliably figure out which signal is using kill, as shown by the following (/bin/ksh and /usr/xpg4/bin/sh):
sleep 1000&
pid=$!
kill -kill $pid
wait $pid
echo $pid was terminated by a SIG$(kill -l $(($?-128))) signal.
Example 2: Returning The Exit Status Of A Process
If the following sequence of commands is run in less than 31 seconds (/bin/ksh and /usr/xpg4/bin/sh):
sleep 257 | sleep 31 &
jobs -l %%
then either of the following commands will return the exit status of the second sleep in the pipeline:
wait <pid of sleep 31>
wait %%
ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of wait: LANG, LC_ALL, LC_CTYPE, LC_MES-
SAGES, and NLSPATH.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWcsu |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
SEE ALSO csh(1), jobs(1), ksh(1), sh(1), attributes(5), environ(5), standards(5)SunOS 5.10 12 Dec 1997 wait(1)