Thursday 15 October 2009

unix : make a manual run process is not killed or dead after you close terminal?

First what is PID 1??

PID 1 is for /sbin/init (can be check by ps 1 in xterm)

it is the first and important process that manage your PC.

Now, when you open xterm and run a command for example gedit.
The gedit will be having parent PID of your xterm.
Hence when you close the xterm, the gedit will also be closed...

How to avoid this??

1. use nohup, with this way after you close the xterm, the gedit Parent PID will be the PID 1.
type : "nohup gedit" inside xterm.
2. create script, and inside that file put "gedit &", and run the script.

Note:
if you try to run it at background, like running "gedit &" in xterm directly (not in a script),
then you close the xterm, the gedit will be closed as well. Because the gedit Parent PID is still the xterm.


>>>>>>>>>>>>>>>>>>>


Pertama apa itu PID 1??

PID 1 adalah untuk /sbin/init (dapat diperiksa apa "id 1" di xterm, tulis "ps 1")
ini adalah proses pertama dan proses penting yang mengelola PC Anda.

Sekarang, ketika Anda membuka xterm dan menjalankan perintah misalnya gedit.
Yang gedit akan memiliki orangtua PID xterm Anda.
Karena itu bila Anda menutup xterm, yang gedit juga akan ditutup ...

Bagaimana menghindari hal ini??

1. menggunakan nohup, dengan cara ini setelah Anda menutup xterm, yang gedit akan Parent PID 1. ketik "nohup gedit" in xterm.
2. membuat file script, dan di dalam file itu tulis "gedit &", dan jalankan script.

Catatan:
jika Anda mencoba untuk menjalankannya di latar belakang, seperti menjalankan "gedit &" di xterm secara langsung (tidak dalam naskah),maka saat Anda menutup xterm, yang gedit akan ditutup juga. Karena Parent PID gedit masih xterm.

No comments:

Post a Comment