nohup
nohup is a POSIX command which means "no hang up". Its purpose is to execute a command such that it ignores the HUP (hangup) signal and therefore does not stop when the user logs out.
Output that would normally go to the terminal goes to a file called nohup.out, if it has not already been redirected.
Use
The first of the commands below starts the program abcd in the background in such a way that the subsequent logout does not stop it.
$ nohupabcd&$ exitNote that these methods prevent the process from being sent a 'stop' signal on logout, but if input/output is being received for these standard I/O files (stdin, stdout, or stderr), they will still hang the terminal.[1] See Overcoming hanging, below.
nohup is often used in combination with the nice command to run processes on a lower priority.
$ nohupniceabcd&$ exitImplementations
Some shells (e.g. bash) provide a shell builtin that may be used to prevent SIGHUP being sent or propagated to existing jobs, even if they were not started with nohup. In bash, this can be obtained by using disown -h job; using the same builtin without arguments removes the job from the job table, which also implies that the job will not receive the signal. Before using disown on an active job, it should be stopped by Ctrl-Z, and continued in the background by the bg command.[2] Another relevant bash option is shopt huponexit, which automatically sends the HUP signal to jobs when the shell is exiting normally.[3]
The AIX and Solaris versions of nohup have a -p option that modifies a running process to ignore future SIGHUP signals. Unlike the above-described disown builtin of bash, nohup -p accepts process IDs.[4]
The nohup command has also been ported to the IBM i operating system.[5]
Overcoming hanging
لاحظ أن استخدام خيار "nohupping" في العمليات الخلفية يُستخدم عادةً لتجنب إنهائها عند تسجيل الخروج من جلسة SSH عن بُعد . وثمة مشكلة أخرى شائعة في هذه الحالة، وهي أن SSH يرفض تسجيل الخروج ("يتوقف")، لأنه يرفض فقدان أي بيانات من/إلى العمليات الخلفية. [ 6 ] [ 7 ] ويمكن التغلب على هذه المشكلة أيضًا بإعادة توجيه جميع مسارات الإدخال/الإخراج الثلاثة.
$ nohup ./myprogram > foo.out 2 > foo.err < /dev/null &تجدر الإشارة أيضًا إلى أن إغلاق جلسة SSH لا يرسل دائمًا إشارة HUP إلى العمليات التابعة، كما هو الحال عندما لا يتم تخصيص طرفية وهمية . [ 8 ]
البدائل
- يمكن لمُضاعِف المحطات الطرفية تشغيل أمرٍ في جلسة منفصلة، مستقلة عن الطرفية الحالية، ما يعني أنه في حال انتهاء الجلسة الحالية، تستمر الجلسة المنفصلة والعمليات المرتبطة بها في العمل. ويمكن إعادة الاتصال بالجلسة لاحقًا.
- على سبيل المثال، سيؤدي استدعاء الأمر screen التالي إلى تشغيل somescript.sh في خلفية جلسة منفصلة:
$ screen -A -m -d -S somename ./somescript.sh &- يتم استخدام الأمر المدمج disown في بعض أنواع الصدف لإزالة المهام من جدول المهام، أو لتمييز المهام بحيث لا يتم إرسال إشارة SIGHUP عند إنهاء الجلسة.
مراجع
- ↑ "ردًا على: nohup/disown وتسجيل الخروج" . Zsh.org. 2005-02-07. مؤرشف من الأصل في 2009-05-18 . تم الاطلاع عليه في 2009-06-10 .
- ↑ دليل مرجعي لـ Bash، مؤرشف بتاريخ 3 ديسمبر 2010 في Wayback Machine . Gnu.org. تم الاطلاع عليه بتاريخ 13 أبريل 2015.
- ↑ دليل مرجعي لـ Bash، مؤرشف بتاريخ 3 ديسمبر 2010 في Wayback Machine . Gnu.org. تم الاطلاع عليه بتاريخ 13 أبريل 2015.
- ↑ مركز معارف IBM ، مؤرشف بتاريخ 15 أكتوبر 2014 على موقع Wayback Machine . 01.ibm.com (26 مارس 2015). تم الاطلاع عليه بتاريخ 13 أبريل 2015.
- ↑ آي بي إم . "برمجة Qshell لنظام IBM System i الإصدار 7.2" (ملف PDF) . آي بي إم . تم الاطلاع عليه بتاريخ 5 سبتمبر 2020 .
- ↑ "الأسئلة الشائعة حول SSH" . Snailbook.com. مؤرشف من الأصل بتاريخ 22 يناير 2009. تم الاطلاع عليه بتاريخ 10 يونيو 2009 .
- ↑ "أسئلة وأجوبة حول OpenSSH" . Openssh.com. 2005-09-20. مؤرشف من الأصل في 2009-07-10 . تم الاطلاع عليه في 2009-06-10 .
- ↑ "الخطأ رقم 396 - عمليات sshd اليتيمة عند عدم تخصيص طرفية افتراضية" . Bugzilla.mindrot.org . تم الاطلاع عليه بتاريخ 10-06-2009 .
روابط خارجية
- nohup من صفحات دليل سولاريس
- أدوات يونكس SUS2008
- أوامر IBM i Qshell
