Skip to content Skip to content


Running process in the background with Nohup Running process fona ar Nohup

Linux

I work on remote servers a lot. Es strādāju par attāliem serveriem lot. I use SSH to connect to my servers. I use SSH, lai izveidotu savienojumu ar savu serveri. Quite often I run a process that I need to let run even after I close my SSH connection. Diezgan bieži man palaist procesu, kas man ir nepieciešams, lai ļautu darboties pat tad, kad es cieši manu SSH savienojumu. This could be a shell script that parses through my log files or very large mysql database restoration. Tas varētu būt shell skriptu, kas parses ar manu log failiem vai ļoti lielas mysql datubāzes atjaunošanas. That's when I turn to a Linux command line utility called “nohup”. Tas ir, kad es pievēršos Linux komandrindas lietderība sauc par "nohup". “Nohup” is short for “no hangup”, which translates to “ignore the hang up signal”. "Nohup" ir īss "nē hangup", kas nozīmē "ignorēt piekārt signāls". The “hang up” signal is what happens when you log out. "Hang up" signāls ir tas, kas notiek, ja jūs log out. What “nohup” does is that it allows you to log into your server, launch a process and log out. Ko nozīmē "nohup", tas ir, ka tas ļauj ieiet jūsu serverī, uzsāks procesu un log out. The process keeps running even after you have logged out. Process turpina darboties arī tad, kad esat izgājis. When you log in again you can access that process again, provided its still running. Kad piesakāties atkal jūs varat piekļūt šo procesu vēlreiz, ja tās joprojām darbojas.

The basic syntax of “nohup” is: Pamata sintaksi "nohup" ir:

# nohup [command] & # Nohup [komanda] &

Replace “[command]” with the name of your shell script, or a command. Aizstāt vārdus "[komanda]" ar nosaukumu jūsu shell skriptu, vai komandu. The “&” at the end makes the command or script run as a background process. "&" Beigās dod komandu vai skriptu palaist kā fona procesu. Here's an example of how you would use “nohup” to take a backup of a large mysql database on your remote server. Lūk, kā jūs varētu izmantot "nohup", lai ņemtu backup lielu mysql datubāzi par jūsu attālajā serverī piemērs. First, I log in to my remote server using SSH: Pirmkārt, es pieteiktos uz manu attālā servera, izmantojot SSH:

# ssh calvin@sevenacross.com # Ssh calvin@sevenacross.com

Then I execute the command “mysqldump -ucalvin -phobbes largedatabase > largedatabase.db” in the “nohup” mode by adding a “nohup” before and “&” after the command: Tad es izpildīt komandu "mysqldump-ucalvin-phobbes largedatabase> largedatabase.db" in "nohup" režīmā, pievienojot "nohup" pirms un "&" pēc komandu:

# nohup mysqldump -ucalvin -phobbes largedatabase > largedatabase.db & # Nohup mysqldump-ucalvin-phobbes largedatabase> largedatabase.db &
[1] 3999 [1] 3.999
# nohup: appending output to `nohup.out' # Nohup: pievienojot produkciju "nohup.out"

There are two lines of output that you get. Ir divas rindas no produkcijas, ko jums. The “3999″ in the first line is the process ID of the process that I just spawned, while the “nohup: appending output to `nohup.out'” means that the out put that would usually come to the terminal is being forwarded into a file called “nohup.out” in the directory from which you launched the command. "3.999", kas pirmajā rindā ir process ID process, ka es tikai panākot, lai gan "nohup: pievienojot produkciju" nohup.out "" nozīmē, ka kas izvirzīti, kas parasti ierodas terminālā tiek nosūtīts spēkā failu ar nosaukumu "nohup.out" in directory no kuras jūs uzsāka komandu. You can check if the process is still running by searching through all the running processes using the process ID: Jūs varat pārbaudīt vai process vēl turpinās, meklējot visos ekspluatācijas procesus, izmantojot procesu, ID:

# ps -ef | grep 3999 # Ps-ef | grep 3.999
calvin 3999 29848 0 18:42 ? Calvin 3999 29848 0 18:42? 00:00:00 /usr/bin/mysqldump 00:00:00 / usr / bin / mysqldump
calvin 6575 31852 0 18:44 pts/2 00:00:00 grep 3999 Calvin 6575 31852 0 18:44 pts / 2 00:00:00 grep 3.999

When the process is done running you will see an output in the command line like this: Kad process tiek veikts darba redzēsiet produkcijas komandrindas šādi:

[1]+ Done nohup mysqldump -ucalvin -phobbes largedatabase > largedatabase.db [1] + Done nohup mysqldump-ucalvin-phobbes largedatabase> largedatabase.db

You can check the file “nohup.out” to check for any errors or other messages that were output while the process was running. Jūs varat pārbaudīt faila "nohup.out", lai pārbaudītu jebkuras kļūdas vai citas ziņas, kas tika produkciju, kamēr process darbojas. If the file remains blank that's okay. Ja fails ir tukšs, ka ir labi. It means no messages were output while the process was running. Tas nozīmē, ka nav ziņu tika izejas, kamēr process darbojas.

Posted in Iesūtīts Linux Linux . .

Related Posts: Related Posts:

How to use dstat to monitor your Linux/UNIX server Kā lietot dstat uzraudzīt jūsu Linux / UNIX serveris
How to get detailed information on each running process in Windows Kā iegūt detalizētu informāciju par katru darba procesu Windows
How to use a screensaver as your desktop background in OS X Kā lietot ekrānsaudzētāju, kā darbvirsmas fonu OS X
How to reset a lost MySQL root password Kā lai atjaunotu zaudēto MySQL root paroli
How to blurminal your OS X Terminal Kā blurminal jūsu OS X Terminal

4 Responses 4 Atbildes

Stay in touch with the conversation, subscribe to the Uzturēt kontaktus ar sarunu, abonēt RSS feed for comments on this post RSS barību komentārus par šo ziņu . .

  1. Bobby Cox says Bobby Cox saka

    Hello – Nohup is useful, but if you use screen you can detach and reattach to a terminal at will and have commands running in the background as well. Hello - Nohup ir noderīga, bet, ja jūs izmantojat ekrāna var atdalīt un jauna vajadzēs uz terminālis būs un ir komandas darbojas fonā, kā arī.

    http://www.gnu.org/software/screen/ http://www.gnu.org/software/screen/

    --
    Bobby Bobby

  2. it guy tas puisis says saka

    I recently used the 'nohup' command as sugested for an instance of tshark I wanted to run for a long time. Es nesen izmantota "nohup" komandu sugested par instance tshark es gribēju braukt uz ilgu laiku.

    Nohup worked great. Nohup strādāja lieliski. Thanks guys. Thanks guys.

  3. Parikshit says Parikshit saka

    I am running a PERL script in background using nohup command. Es esmu darba PERL script fona izmantojot nohup komandu. this script prints logs on the screen. šo skriptu izdrukas logs uz ekrāna. Though i used & to run it in background it still prints the logs on the console . Lai gan man izmantot un lai tā varētu darboties fonā tā joprojām drukā uz konsoles logs. How can it be actually run in background so that it shouldn't print anything on the screen . Kā to var reāli darbojas fonā, lai tā nebūtu drukāt neko uz ekrāna.

  4. Jim says Jim saka

    redirect error output to the same file maybe? novirzīt kļūda izeja uz pašu failu maybe?

    nohup mysqldump -ucalvin -phobbes largedatabase >largedatabase.db 2>&1 & nohup mysqldump-ucalvin-phobbes largedatabase> largedatabase.db 2> & 1 &



Some HTML is OK Daži HTML ir OK

or, reply to this post via vai, atbildot uz šo ziņu izmantojot trackback Trackback . .