I have been trying to put a complex multi-threaded process in the background. I am using CentOS 5.3 (a 2.6 kernel). Previously, using a 2.4 kernel, I used the following template successfully.
nohup ./my_process > nohup.08-06-09.out &
This always worked for me. I have conducted dozens of experiments, using simple programs, and have always gotten the above template to work if I followed these rules:
1. The process is a simple script (like #1 below)
2. A compiled program, SimpleTask.c, that frequently calls fflush(stdout)
#1. simply always works.
#2. works as long as I explicitly call fflush to purge the stdout stream.
If I eliminate the fflush call in #2, the "nohup.*.out" file is created, but always has zero length. If I include the fflush call, nohup.*.out is just what I expect, and contains all the terminal output from the process.
So now I need to put a large, complex program online that has minimal terminal output, but preserving that output is essential. This program is built from about 180 source code files, has been 4 years in development and is ready for production, so I MUST background it. 2 years ago, the 2.4 kernel demo version of this program worked fine with nohup.
The new 2.6 kernel version simply will not work with background attempts.
This method:
nohup ./big_process &
doesn't work because the nohup.out file is permanently empty. I don't know exactly what the process is doing, but it seems to be running.
This method:
./big_process &
disown -h
doesn't work because the disowned process is stuck somewhere.
I have tried every combination of things I can think of in terms of explicit redirection of output, redirection of input, ad nauseum...
I have a script that displays the open files of the complex process and the output looks the same except that the filesize of all the files owned by the backgrounded process are all frozen.
Example #1: A script that always works:
#!/bin/sh
# This script prints the date and time once per second
while [ 1 ]
do
date
sleep 1
done
---------- end of script --------------------------------
Example #2: Executable that works as long as fflush is in the loop:
#include <stdio.h>
#include <stdlib.h>
int main (void)
{ while (1)
{
printf("Hello there...\n");
fflush(stdout); // Remove this and nohup.out never contains output
sleep(1);
}
}
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
Select allOpen in new window
by: cjl7Posted on 2009-08-06 at 09:28:04ID: 25035296
Well,
You could use screen as a way to get forward right now.
If all you want to do is detach the program that will work.
About nohup I don't know why it isn't working for you.
//jonas