General :: Create A New Background Process In A KSH "while Read" Loop?
Jun 20, 2010
When I add the line (sleep 5 ) & in the script then the "while read" loop does not read all lines from the file, but only prints the first line.But when I remove the ( sleep 5 ) & from the script, then the script prints all lines as defined in the file.And how to solve the problem? I want to create a new process (for which the sleep is just an example) in the while loop:
First post from a very new Linux user....I am trying to create a BASH script that will allow user to provide multiple directory names, Checks if the directory exists and if not create the directory.
I am using the following code:
Which works fine as long as the user enters a single directory name. How can I modify this so it will process all directory names user enters on the read response?
I know of terminating a command with & and then moving it into the background by pressing Ctrl-Z and then bg [pid], and I also know of nohup. But say you started a process that turned out to take much longer than one expected, is there a way of pulling, so to speak, this process from another terminal screen into the background so that even if I log off from the server the process would continue?
How do you move a running process to the background? For example, type the command sleep 60 on the command line and try moving that process to the background.
I am trying to solve one problem: When i run my process in background it hogs around 96% of CPU. But when ran in foreground, CPU utilization is almost zero. Is there any difference b/n a background and a foreground process wrto CPU utilization?
Because of my English skills I'll try to explain this subject as best I can, thank you for understanding. Fisrt of all, I am running some program on my slackware in background (using standard method - &). I need to make a script, which allows sending command to this process on my machine from another one. Furthermore this program have to be logged out (standard output f.e. ./myprogram > log.out.txt).It might be a separate Program A which runs my Program B but it cannot be screen, because it is not working like I'd like to and it cannot be java, because it's slow and working not the best so to speak
I wonder how one can, if at all, run an X program in the background *in an emulator sub-shell process*. What I mean is to launch a program in an emulator, e.g, by xterm -e gedit
but with gedit (in this example) running in the background from inside the xterm sub-process, so that the xterm will accept other commands. In the above, gedit will run in the foreground, and of course, if you do xterm -e gedit &
then xterm will run in the background, not gedit.In short, I would like to achieve the same thing as "gedit &" as you manually do in xterm, but from another shell. What I aim to do is write an X init script to achieve this result (to have the emulator open and a program or two running from it, in the background, at the X startup).
The first call to "somefunction" works as expected. The function prints "endfunction" and a process in background sleeps 30 seconds. In the second call I thought it should work in the same way, but the script sleeps 30 seconds before it prints "endfunction".Does someone know the reason of this behavior? Is there another way to do a command substitution of a function that has a background process without have to waiting for that process?
I desire to take an image,overlay a text on that image;then, use it as aackground or text document.Would I use Gimp;then,somehow mount the image to a theme for x-window?If so,how?I would use a colored background text for various priority rated documents.I would use a yellow background text document with a red cross;and,a blue text, for medical documents[as an example].
I'm trying to prompt the user to enter Y or N in the middle of a while loop, but the read command is simply drawing in the next value.I'm reading from a simple file full of words (one per line)
I've been reading various tutorials of the boot process but still am not clear. I don't care about grub stage 1 and 1.5 at the starting point of when the root filesystem is loaded into VFS(Virtualfilesystem), who is loading it, and from that point on. 1) Does grub load the root filesystem(read only) into VFS?2) Does the kernel load the root filesystem(read only) into VFS?3) Does INIT load the root filesystem(read only) into VFS?after this is concluded....Does INIT or the Kernel create the real root filesystem(rw)...right before the pivot.root
I am trying to develop a process monitor, or use existing monitors to achieve the below given actions.
1) Restart a processes if it crashes. 2) Restart a processes if it is stuck in an infinite loop.
The sample code below describes the structure of the process.
while(1) { statement 1.... statement 2.... while (1) {
[Code].....
The goal is to restart the process if it is stuck in a loop, inside the outer while loop. Given this scenario, what would be the most efficient way to monitor such a process?
A sample solution would look something like this: statement 3 will write to file1 every time it is executed and we know that the maximum execution time of the outer while loop is 30 seconds. A second, timer driven process, checks for file1 being modified every 30 seconds. If the file is not modified, process 1 will be restarted assuming, process1 is stuck in a while loop.
I had an interview , where the interviewer asked me the question "How to create and call a process in unix". I answered that we can use the command FORK()/ CLONE() to create a process. But I didn't have the answer for the second question, how to call a process.
I am trying to read the names of hosts from a file and do a ssh to see if processes are all running or not.
Here is the outer loop that is causing problem:
hosts.lst is a text file that has the host names in each line.
The problem is that the loop just breaks after the first run. Somehow while read line becomes invalid when the body of the loop does the ssh and returns.
I have a process A running in the background. When I start another process B also in the background, the system hangs the moment I hit any key. Process A and B communicate over a socket. Iam not even able to do a telnet to the system. Is there any precautions that I need to take while running in background