How to know the process PID in linux machine












0














I am launching an installer from java to install a software on linux, I want to to know the "process id and image name" of it.



In windows I able to get it by using tasklist command, but in linux I have not been able to do the same. I tried with ps -ef and ps -A commands, but its not showing the image name or PID of process.



Is there any command to get it these values?










share|improve this question















migrated from stackoverflow.com Mar 29 '13 at 12:40


This question came from our site for professional and enthusiast programmers.




















    0














    I am launching an installer from java to install a software on linux, I want to to know the "process id and image name" of it.



    In windows I able to get it by using tasklist command, but in linux I have not been able to do the same. I tried with ps -ef and ps -A commands, but its not showing the image name or PID of process.



    Is there any command to get it these values?










    share|improve this question















    migrated from stackoverflow.com Mar 29 '13 at 12:40


    This question came from our site for professional and enthusiast programmers.


















      0












      0








      0







      I am launching an installer from java to install a software on linux, I want to to know the "process id and image name" of it.



      In windows I able to get it by using tasklist command, but in linux I have not been able to do the same. I tried with ps -ef and ps -A commands, but its not showing the image name or PID of process.



      Is there any command to get it these values?










      share|improve this question















      I am launching an installer from java to install a software on linux, I want to to know the "process id and image name" of it.



      In windows I able to get it by using tasklist command, but in linux I have not been able to do the same. I tried with ps -ef and ps -A commands, but its not showing the image name or PID of process.



      Is there any command to get it these values?







      linux java






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 5 '13 at 12:45









      Chenmunka

      2,79481931




      2,79481931










      asked Mar 29 '13 at 5:32









      kgopi

      113




      113




      migrated from stackoverflow.com Mar 29 '13 at 12:40


      This question came from our site for professional and enthusiast programmers.






      migrated from stackoverflow.com Mar 29 '13 at 12:40


      This question came from our site for professional and enthusiast programmers.
























          5 Answers
          5






          active

          oldest

          votes


















          1














          Most modern Linux distros have handy command pgrep (process grep), which was created just for this purpose. Use it like this:



          pgrep -lf programname


          Unlike naive ps ax | grep programname, pgrep knows how to not display process id of itself.



          There is also complementary utility pkill, which can kill process by name (or send other signals).






          share|improve this answer





















          • I tried it, it didn't worked....... Here the thing is I even don't know the process name, say for example in windows I launched a installer called xxx.exe, then I am able ti see the procee title as "xxx"(window title/process name) with that I am recognizing the windows existance............ In the same way I want to do it for linux(but noprocess existed with title name) Is there any command to get it –
            – kgopi
            Mar 29 '13 at 5:45










          • You should know process name or program name. If you don't, carefully inspect output of ps ax. Also, starting top or atop in another console might shed some light in what is actual process name for the installer - it is most likely to be top process once install begins.
            – mvp
            Mar 29 '13 at 5:49










          • I want to the know process name of my installer program
            – kgopi
            Mar 29 '13 at 6:04










          • That's what I told you - start top in another console, then start your installer, quickly switch back to top and watch which process is using most of CPU.
            – mvp
            Mar 29 '13 at 6:06



















          0














          Try ps -aef | grep your_process_name, replace your_process_name with your installer name.



          Hope this helps !!






          share|improve this answer





















          • Hi Alankar, Here the thing is I even don't know the process name, say for example in windows I launched a installer called xxx.exe, then I am able ti see the procee title as "xxx"(window title/process name) with that I am recognizing the windows existance............ In the same way I want to do it for linux(but no process existed with title name) Is there any command to get it
            – kgopi
            Mar 29 '13 at 5:43










          • @kgopi. How you are starting your installer in linux.
            – Alankar
            Mar 29 '13 at 5:50










          • through command prompt like first I am navigating to the installer folder and then I am executing "./xxx.bin" command
            – kgopi
            Mar 29 '13 at 5:53










          • Often (e.g. for NVIDIA drivers) the *.run is a huge sh script, so with ps auxw you see the sh process; also top will show you all the most active processes...
            – Basile Starynkevitch
            Mar 29 '13 at 5:56






          • 1




            @kgopi Then you can give that xxx only after grep something like this pa -aef | grep -i xxx
            – Alankar
            Mar 29 '13 at 5:57



















          0














          It is generally best to capture the process ID at the time you launch it rather than trying to find it later on.



          If using the C API, you get the PID of the spawned process as the return value from fork or vfork in the mother process.



          In a Bourne derived shell you use $! immediately after starting it.






          share|improve this answer























          • I am using java to launch the installer in linux machine like this runtime.exe("xxx.bin"). so, through java also can i get the PIdprocess name
            – kgopi
            Mar 29 '13 at 6:07










          • Can't help you much with Java. There are at least two older Stack Overflow threads on the subject, but neither has a really good answer.
            – dmckee
            Mar 29 '13 at 6:15



















          0














          It seems that your are looking for a Linux centric solution rather than a portable one. On Linux the easy, efficient and reliable way to get the information you need from Java is to use the proc filesystem, and especially the /proc/self directory. The man 5 proc manpage describe each file.



          The pid is first field of /proc/self/stat. The image name is the second one.



          It is very easy to write a class to wrap these calls. It will be only a few lines of code doing basic IO: fast and robust. Using third party programs is harder to get right and less efficient.



          This solution is not portable since most of the Unix systems do not have a proc filesystem. You have four options from the best to the worst, IMHO:




          • Capture the information you need before starting the process: Could be easy or not depending of your application

          • Find clean & system specific implementations like the proc file system for Linux

          • Use unspecified API. RuntimeMXBean.getName() usually returns the pid, you can also use reflection to get access to java.lang.UnixProcess.pid. Implementation can differs between JVM and can change at any time. Acceptable solutions if you control the environment.

          • Write native code to access the POSIX API

          • Use external tools like ps


          If you decide to rely on external tools then you should be very careful about portability (options and output can differs greatly between two OS) and locale settings.






          share|improve this answer































            0














            if it is a graphical installer you can run this one-liner in a terminal:



            ps -fp $(xprop _NET_WM_PID | cut -d' ' -f3)


            your mouse cursor will change to a crosshair. Now click on the window in question. you should now see process information printed in the terminal.






            share|improve this answer





















              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f575231%2fhow-to-know-the-process-pid-in-linux-machine%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              5 Answers
              5






              active

              oldest

              votes








              5 Answers
              5






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              Most modern Linux distros have handy command pgrep (process grep), which was created just for this purpose. Use it like this:



              pgrep -lf programname


              Unlike naive ps ax | grep programname, pgrep knows how to not display process id of itself.



              There is also complementary utility pkill, which can kill process by name (or send other signals).






              share|improve this answer





















              • I tried it, it didn't worked....... Here the thing is I even don't know the process name, say for example in windows I launched a installer called xxx.exe, then I am able ti see the procee title as "xxx"(window title/process name) with that I am recognizing the windows existance............ In the same way I want to do it for linux(but noprocess existed with title name) Is there any command to get it –
                – kgopi
                Mar 29 '13 at 5:45










              • You should know process name or program name. If you don't, carefully inspect output of ps ax. Also, starting top or atop in another console might shed some light in what is actual process name for the installer - it is most likely to be top process once install begins.
                – mvp
                Mar 29 '13 at 5:49










              • I want to the know process name of my installer program
                – kgopi
                Mar 29 '13 at 6:04










              • That's what I told you - start top in another console, then start your installer, quickly switch back to top and watch which process is using most of CPU.
                – mvp
                Mar 29 '13 at 6:06
















              1














              Most modern Linux distros have handy command pgrep (process grep), which was created just for this purpose. Use it like this:



              pgrep -lf programname


              Unlike naive ps ax | grep programname, pgrep knows how to not display process id of itself.



              There is also complementary utility pkill, which can kill process by name (or send other signals).






              share|improve this answer





















              • I tried it, it didn't worked....... Here the thing is I even don't know the process name, say for example in windows I launched a installer called xxx.exe, then I am able ti see the procee title as "xxx"(window title/process name) with that I am recognizing the windows existance............ In the same way I want to do it for linux(but noprocess existed with title name) Is there any command to get it –
                – kgopi
                Mar 29 '13 at 5:45










              • You should know process name or program name. If you don't, carefully inspect output of ps ax. Also, starting top or atop in another console might shed some light in what is actual process name for the installer - it is most likely to be top process once install begins.
                – mvp
                Mar 29 '13 at 5:49










              • I want to the know process name of my installer program
                – kgopi
                Mar 29 '13 at 6:04










              • That's what I told you - start top in another console, then start your installer, quickly switch back to top and watch which process is using most of CPU.
                – mvp
                Mar 29 '13 at 6:06














              1












              1








              1






              Most modern Linux distros have handy command pgrep (process grep), which was created just for this purpose. Use it like this:



              pgrep -lf programname


              Unlike naive ps ax | grep programname, pgrep knows how to not display process id of itself.



              There is also complementary utility pkill, which can kill process by name (or send other signals).






              share|improve this answer












              Most modern Linux distros have handy command pgrep (process grep), which was created just for this purpose. Use it like this:



              pgrep -lf programname


              Unlike naive ps ax | grep programname, pgrep knows how to not display process id of itself.



              There is also complementary utility pkill, which can kill process by name (or send other signals).







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 29 '13 at 5:36









              mvp

              3,3421523




              3,3421523












              • I tried it, it didn't worked....... Here the thing is I even don't know the process name, say for example in windows I launched a installer called xxx.exe, then I am able ti see the procee title as "xxx"(window title/process name) with that I am recognizing the windows existance............ In the same way I want to do it for linux(but noprocess existed with title name) Is there any command to get it –
                – kgopi
                Mar 29 '13 at 5:45










              • You should know process name or program name. If you don't, carefully inspect output of ps ax. Also, starting top or atop in another console might shed some light in what is actual process name for the installer - it is most likely to be top process once install begins.
                – mvp
                Mar 29 '13 at 5:49










              • I want to the know process name of my installer program
                – kgopi
                Mar 29 '13 at 6:04










              • That's what I told you - start top in another console, then start your installer, quickly switch back to top and watch which process is using most of CPU.
                – mvp
                Mar 29 '13 at 6:06


















              • I tried it, it didn't worked....... Here the thing is I even don't know the process name, say for example in windows I launched a installer called xxx.exe, then I am able ti see the procee title as "xxx"(window title/process name) with that I am recognizing the windows existance............ In the same way I want to do it for linux(but noprocess existed with title name) Is there any command to get it –
                – kgopi
                Mar 29 '13 at 5:45










              • You should know process name or program name. If you don't, carefully inspect output of ps ax. Also, starting top or atop in another console might shed some light in what is actual process name for the installer - it is most likely to be top process once install begins.
                – mvp
                Mar 29 '13 at 5:49










              • I want to the know process name of my installer program
                – kgopi
                Mar 29 '13 at 6:04










              • That's what I told you - start top in another console, then start your installer, quickly switch back to top and watch which process is using most of CPU.
                – mvp
                Mar 29 '13 at 6:06
















              I tried it, it didn't worked....... Here the thing is I even don't know the process name, say for example in windows I launched a installer called xxx.exe, then I am able ti see the procee title as "xxx"(window title/process name) with that I am recognizing the windows existance............ In the same way I want to do it for linux(but noprocess existed with title name) Is there any command to get it –
              – kgopi
              Mar 29 '13 at 5:45




              I tried it, it didn't worked....... Here the thing is I even don't know the process name, say for example in windows I launched a installer called xxx.exe, then I am able ti see the procee title as "xxx"(window title/process name) with that I am recognizing the windows existance............ In the same way I want to do it for linux(but noprocess existed with title name) Is there any command to get it –
              – kgopi
              Mar 29 '13 at 5:45












              You should know process name or program name. If you don't, carefully inspect output of ps ax. Also, starting top or atop in another console might shed some light in what is actual process name for the installer - it is most likely to be top process once install begins.
              – mvp
              Mar 29 '13 at 5:49




              You should know process name or program name. If you don't, carefully inspect output of ps ax. Also, starting top or atop in another console might shed some light in what is actual process name for the installer - it is most likely to be top process once install begins.
              – mvp
              Mar 29 '13 at 5:49












              I want to the know process name of my installer program
              – kgopi
              Mar 29 '13 at 6:04




              I want to the know process name of my installer program
              – kgopi
              Mar 29 '13 at 6:04












              That's what I told you - start top in another console, then start your installer, quickly switch back to top and watch which process is using most of CPU.
              – mvp
              Mar 29 '13 at 6:06




              That's what I told you - start top in another console, then start your installer, quickly switch back to top and watch which process is using most of CPU.
              – mvp
              Mar 29 '13 at 6:06













              0














              Try ps -aef | grep your_process_name, replace your_process_name with your installer name.



              Hope this helps !!






              share|improve this answer





















              • Hi Alankar, Here the thing is I even don't know the process name, say for example in windows I launched a installer called xxx.exe, then I am able ti see the procee title as "xxx"(window title/process name) with that I am recognizing the windows existance............ In the same way I want to do it for linux(but no process existed with title name) Is there any command to get it
                – kgopi
                Mar 29 '13 at 5:43










              • @kgopi. How you are starting your installer in linux.
                – Alankar
                Mar 29 '13 at 5:50










              • through command prompt like first I am navigating to the installer folder and then I am executing "./xxx.bin" command
                – kgopi
                Mar 29 '13 at 5:53










              • Often (e.g. for NVIDIA drivers) the *.run is a huge sh script, so with ps auxw you see the sh process; also top will show you all the most active processes...
                – Basile Starynkevitch
                Mar 29 '13 at 5:56






              • 1




                @kgopi Then you can give that xxx only after grep something like this pa -aef | grep -i xxx
                – Alankar
                Mar 29 '13 at 5:57
















              0














              Try ps -aef | grep your_process_name, replace your_process_name with your installer name.



              Hope this helps !!






              share|improve this answer





















              • Hi Alankar, Here the thing is I even don't know the process name, say for example in windows I launched a installer called xxx.exe, then I am able ti see the procee title as "xxx"(window title/process name) with that I am recognizing the windows existance............ In the same way I want to do it for linux(but no process existed with title name) Is there any command to get it
                – kgopi
                Mar 29 '13 at 5:43










              • @kgopi. How you are starting your installer in linux.
                – Alankar
                Mar 29 '13 at 5:50










              • through command prompt like first I am navigating to the installer folder and then I am executing "./xxx.bin" command
                – kgopi
                Mar 29 '13 at 5:53










              • Often (e.g. for NVIDIA drivers) the *.run is a huge sh script, so with ps auxw you see the sh process; also top will show you all the most active processes...
                – Basile Starynkevitch
                Mar 29 '13 at 5:56






              • 1




                @kgopi Then you can give that xxx only after grep something like this pa -aef | grep -i xxx
                – Alankar
                Mar 29 '13 at 5:57














              0












              0








              0






              Try ps -aef | grep your_process_name, replace your_process_name with your installer name.



              Hope this helps !!






              share|improve this answer












              Try ps -aef | grep your_process_name, replace your_process_name with your installer name.



              Hope this helps !!







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 29 '13 at 5:36







              Alankar



















              • Hi Alankar, Here the thing is I even don't know the process name, say for example in windows I launched a installer called xxx.exe, then I am able ti see the procee title as "xxx"(window title/process name) with that I am recognizing the windows existance............ In the same way I want to do it for linux(but no process existed with title name) Is there any command to get it
                – kgopi
                Mar 29 '13 at 5:43










              • @kgopi. How you are starting your installer in linux.
                – Alankar
                Mar 29 '13 at 5:50










              • through command prompt like first I am navigating to the installer folder and then I am executing "./xxx.bin" command
                – kgopi
                Mar 29 '13 at 5:53










              • Often (e.g. for NVIDIA drivers) the *.run is a huge sh script, so with ps auxw you see the sh process; also top will show you all the most active processes...
                – Basile Starynkevitch
                Mar 29 '13 at 5:56






              • 1




                @kgopi Then you can give that xxx only after grep something like this pa -aef | grep -i xxx
                – Alankar
                Mar 29 '13 at 5:57


















              • Hi Alankar, Here the thing is I even don't know the process name, say for example in windows I launched a installer called xxx.exe, then I am able ti see the procee title as "xxx"(window title/process name) with that I am recognizing the windows existance............ In the same way I want to do it for linux(but no process existed with title name) Is there any command to get it
                – kgopi
                Mar 29 '13 at 5:43










              • @kgopi. How you are starting your installer in linux.
                – Alankar
                Mar 29 '13 at 5:50










              • through command prompt like first I am navigating to the installer folder and then I am executing "./xxx.bin" command
                – kgopi
                Mar 29 '13 at 5:53










              • Often (e.g. for NVIDIA drivers) the *.run is a huge sh script, so with ps auxw you see the sh process; also top will show you all the most active processes...
                – Basile Starynkevitch
                Mar 29 '13 at 5:56






              • 1




                @kgopi Then you can give that xxx only after grep something like this pa -aef | grep -i xxx
                – Alankar
                Mar 29 '13 at 5:57
















              Hi Alankar, Here the thing is I even don't know the process name, say for example in windows I launched a installer called xxx.exe, then I am able ti see the procee title as "xxx"(window title/process name) with that I am recognizing the windows existance............ In the same way I want to do it for linux(but no process existed with title name) Is there any command to get it
              – kgopi
              Mar 29 '13 at 5:43




              Hi Alankar, Here the thing is I even don't know the process name, say for example in windows I launched a installer called xxx.exe, then I am able ti see the procee title as "xxx"(window title/process name) with that I am recognizing the windows existance............ In the same way I want to do it for linux(but no process existed with title name) Is there any command to get it
              – kgopi
              Mar 29 '13 at 5:43












              @kgopi. How you are starting your installer in linux.
              – Alankar
              Mar 29 '13 at 5:50




              @kgopi. How you are starting your installer in linux.
              – Alankar
              Mar 29 '13 at 5:50












              through command prompt like first I am navigating to the installer folder and then I am executing "./xxx.bin" command
              – kgopi
              Mar 29 '13 at 5:53




              through command prompt like first I am navigating to the installer folder and then I am executing "./xxx.bin" command
              – kgopi
              Mar 29 '13 at 5:53












              Often (e.g. for NVIDIA drivers) the *.run is a huge sh script, so with ps auxw you see the sh process; also top will show you all the most active processes...
              – Basile Starynkevitch
              Mar 29 '13 at 5:56




              Often (e.g. for NVIDIA drivers) the *.run is a huge sh script, so with ps auxw you see the sh process; also top will show you all the most active processes...
              – Basile Starynkevitch
              Mar 29 '13 at 5:56




              1




              1




              @kgopi Then you can give that xxx only after grep something like this pa -aef | grep -i xxx
              – Alankar
              Mar 29 '13 at 5:57




              @kgopi Then you can give that xxx only after grep something like this pa -aef | grep -i xxx
              – Alankar
              Mar 29 '13 at 5:57











              0














              It is generally best to capture the process ID at the time you launch it rather than trying to find it later on.



              If using the C API, you get the PID of the spawned process as the return value from fork or vfork in the mother process.



              In a Bourne derived shell you use $! immediately after starting it.






              share|improve this answer























              • I am using java to launch the installer in linux machine like this runtime.exe("xxx.bin"). so, through java also can i get the PIdprocess name
                – kgopi
                Mar 29 '13 at 6:07










              • Can't help you much with Java. There are at least two older Stack Overflow threads on the subject, but neither has a really good answer.
                – dmckee
                Mar 29 '13 at 6:15
















              0














              It is generally best to capture the process ID at the time you launch it rather than trying to find it later on.



              If using the C API, you get the PID of the spawned process as the return value from fork or vfork in the mother process.



              In a Bourne derived shell you use $! immediately after starting it.






              share|improve this answer























              • I am using java to launch the installer in linux machine like this runtime.exe("xxx.bin"). so, through java also can i get the PIdprocess name
                – kgopi
                Mar 29 '13 at 6:07










              • Can't help you much with Java. There are at least two older Stack Overflow threads on the subject, but neither has a really good answer.
                – dmckee
                Mar 29 '13 at 6:15














              0












              0








              0






              It is generally best to capture the process ID at the time you launch it rather than trying to find it later on.



              If using the C API, you get the PID of the spawned process as the return value from fork or vfork in the mother process.



              In a Bourne derived shell you use $! immediately after starting it.






              share|improve this answer














              It is generally best to capture the process ID at the time you launch it rather than trying to find it later on.



              If using the C API, you get the PID of the spawned process as the return value from fork or vfork in the mother process.



              In a Bourne derived shell you use $! immediately after starting it.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 23 '17 at 12:41









              Community

              1




              1










              answered Mar 29 '13 at 6:02









              dmckee

              7,04612240




              7,04612240












              • I am using java to launch the installer in linux machine like this runtime.exe("xxx.bin"). so, through java also can i get the PIdprocess name
                – kgopi
                Mar 29 '13 at 6:07










              • Can't help you much with Java. There are at least two older Stack Overflow threads on the subject, but neither has a really good answer.
                – dmckee
                Mar 29 '13 at 6:15


















              • I am using java to launch the installer in linux machine like this runtime.exe("xxx.bin"). so, through java also can i get the PIdprocess name
                – kgopi
                Mar 29 '13 at 6:07










              • Can't help you much with Java. There are at least two older Stack Overflow threads on the subject, but neither has a really good answer.
                – dmckee
                Mar 29 '13 at 6:15
















              I am using java to launch the installer in linux machine like this runtime.exe("xxx.bin"). so, through java also can i get the PIdprocess name
              – kgopi
              Mar 29 '13 at 6:07




              I am using java to launch the installer in linux machine like this runtime.exe("xxx.bin"). so, through java also can i get the PIdprocess name
              – kgopi
              Mar 29 '13 at 6:07












              Can't help you much with Java. There are at least two older Stack Overflow threads on the subject, but neither has a really good answer.
              – dmckee
              Mar 29 '13 at 6:15




              Can't help you much with Java. There are at least two older Stack Overflow threads on the subject, but neither has a really good answer.
              – dmckee
              Mar 29 '13 at 6:15











              0














              It seems that your are looking for a Linux centric solution rather than a portable one. On Linux the easy, efficient and reliable way to get the information you need from Java is to use the proc filesystem, and especially the /proc/self directory. The man 5 proc manpage describe each file.



              The pid is first field of /proc/self/stat. The image name is the second one.



              It is very easy to write a class to wrap these calls. It will be only a few lines of code doing basic IO: fast and robust. Using third party programs is harder to get right and less efficient.



              This solution is not portable since most of the Unix systems do not have a proc filesystem. You have four options from the best to the worst, IMHO:




              • Capture the information you need before starting the process: Could be easy or not depending of your application

              • Find clean & system specific implementations like the proc file system for Linux

              • Use unspecified API. RuntimeMXBean.getName() usually returns the pid, you can also use reflection to get access to java.lang.UnixProcess.pid. Implementation can differs between JVM and can change at any time. Acceptable solutions if you control the environment.

              • Write native code to access the POSIX API

              • Use external tools like ps


              If you decide to rely on external tools then you should be very careful about portability (options and output can differs greatly between two OS) and locale settings.






              share|improve this answer




























                0














                It seems that your are looking for a Linux centric solution rather than a portable one. On Linux the easy, efficient and reliable way to get the information you need from Java is to use the proc filesystem, and especially the /proc/self directory. The man 5 proc manpage describe each file.



                The pid is first field of /proc/self/stat. The image name is the second one.



                It is very easy to write a class to wrap these calls. It will be only a few lines of code doing basic IO: fast and robust. Using third party programs is harder to get right and less efficient.



                This solution is not portable since most of the Unix systems do not have a proc filesystem. You have four options from the best to the worst, IMHO:




                • Capture the information you need before starting the process: Could be easy or not depending of your application

                • Find clean & system specific implementations like the proc file system for Linux

                • Use unspecified API. RuntimeMXBean.getName() usually returns the pid, you can also use reflection to get access to java.lang.UnixProcess.pid. Implementation can differs between JVM and can change at any time. Acceptable solutions if you control the environment.

                • Write native code to access the POSIX API

                • Use external tools like ps


                If you decide to rely on external tools then you should be very careful about portability (options and output can differs greatly between two OS) and locale settings.






                share|improve this answer


























                  0












                  0








                  0






                  It seems that your are looking for a Linux centric solution rather than a portable one. On Linux the easy, efficient and reliable way to get the information you need from Java is to use the proc filesystem, and especially the /proc/self directory. The man 5 proc manpage describe each file.



                  The pid is first field of /proc/self/stat. The image name is the second one.



                  It is very easy to write a class to wrap these calls. It will be only a few lines of code doing basic IO: fast and robust. Using third party programs is harder to get right and less efficient.



                  This solution is not portable since most of the Unix systems do not have a proc filesystem. You have four options from the best to the worst, IMHO:




                  • Capture the information you need before starting the process: Could be easy or not depending of your application

                  • Find clean & system specific implementations like the proc file system for Linux

                  • Use unspecified API. RuntimeMXBean.getName() usually returns the pid, you can also use reflection to get access to java.lang.UnixProcess.pid. Implementation can differs between JVM and can change at any time. Acceptable solutions if you control the environment.

                  • Write native code to access the POSIX API

                  • Use external tools like ps


                  If you decide to rely on external tools then you should be very careful about portability (options and output can differs greatly between two OS) and locale settings.






                  share|improve this answer














                  It seems that your are looking for a Linux centric solution rather than a portable one. On Linux the easy, efficient and reliable way to get the information you need from Java is to use the proc filesystem, and especially the /proc/self directory. The man 5 proc manpage describe each file.



                  The pid is first field of /proc/self/stat. The image name is the second one.



                  It is very easy to write a class to wrap these calls. It will be only a few lines of code doing basic IO: fast and robust. Using third party programs is harder to get right and less efficient.



                  This solution is not portable since most of the Unix systems do not have a proc filesystem. You have four options from the best to the worst, IMHO:




                  • Capture the information you need before starting the process: Could be easy or not depending of your application

                  • Find clean & system specific implementations like the proc file system for Linux

                  • Use unspecified API. RuntimeMXBean.getName() usually returns the pid, you can also use reflection to get access to java.lang.UnixProcess.pid. Implementation can differs between JVM and can change at any time. Acceptable solutions if you control the environment.

                  • Write native code to access the POSIX API

                  • Use external tools like ps


                  If you decide to rely on external tools then you should be very careful about portability (options and output can differs greatly between two OS) and locale settings.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 31 '13 at 15:05

























                  answered Mar 31 '13 at 14:53









                  Clément MATHIEU

                  1085




                  1085























                      0














                      if it is a graphical installer you can run this one-liner in a terminal:



                      ps -fp $(xprop _NET_WM_PID | cut -d' ' -f3)


                      your mouse cursor will change to a crosshair. Now click on the window in question. you should now see process information printed in the terminal.






                      share|improve this answer


























                        0














                        if it is a graphical installer you can run this one-liner in a terminal:



                        ps -fp $(xprop _NET_WM_PID | cut -d' ' -f3)


                        your mouse cursor will change to a crosshair. Now click on the window in question. you should now see process information printed in the terminal.






                        share|improve this answer
























                          0












                          0








                          0






                          if it is a graphical installer you can run this one-liner in a terminal:



                          ps -fp $(xprop _NET_WM_PID | cut -d' ' -f3)


                          your mouse cursor will change to a crosshair. Now click on the window in question. you should now see process information printed in the terminal.






                          share|improve this answer












                          if it is a graphical installer you can run this one-liner in a terminal:



                          ps -fp $(xprop _NET_WM_PID | cut -d' ' -f3)


                          your mouse cursor will change to a crosshair. Now click on the window in question. you should now see process information printed in the terminal.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 21 '18 at 19:38









                          qwertz

                          1




                          1






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f575231%2fhow-to-know-the-process-pid-in-linux-machine%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                              Mangá

                              Eduardo VII do Reino Unido