LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to run a shell script in a background? (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-run-a-shell-script-in-a-background-608669/)

anandv_1234 12-23-2007 02:16 AM

How to run a shell script in a background?
 
Dear Folks,

I wanted to run a particular shell program in a background,
how do we do that...


i have another query also, that is how to find a creation date of the file..

Thanks in advance..


Thanks and Regards,
V.Anand,
Bangalore.

the_imax 12-23-2007 02:46 AM

but an & at the end of the command to run it in background

like
./myscript&

this will keep your terminal free and command will keep running in background

I am not sure about the file creation date, may be someone else can help

UgoBoss 12-23-2007 03:01 AM

Quote:

Originally Posted by anandv_1234 (Post 2999436)
i have another query also, that is how to find a creation date of the file..

This is not possible: unix stores only time of last access, time of last modification and time of last inode change

matthewg42 12-23-2007 03:03 AM

Note that for most commands, if you run them in the background using the & after the command, they will terminate when the terminal is closed. This is because the operating system sends the SIGHUP (hang up) signal to background jobs when a terminal closes, and mos programs terminate on receipt of this signal.

You can prevent the signal from getting to the program by starting it like this:
Code:

nohup command &
The nohup stands for "no hangup", referring to the signal mentioned above.

As for the time, unix-like filesystems do not store the creation time for files. You have three time stamps to choose from:
  1. atime - the time the file was last accessed (e.g. read)
  2. mtime - the time the file contents were last modified (e.g. appended to)
  3. ctime - time of last change to the file contents or the file meta-data (e.g. permissions change).
Probably the one you want is the mtime. You can get this for a specific file using the stat command, like this:
Code:

stat -c %y filename
Of using the -l option to ls will also display the mtime, although the format changes more, so if you are trying to use it in a script, the stat method is probably more suitable.


All times are GMT -5. The time now is 07:38 PM.