How to open program from process id?
Is there any way to open program which is running in background. I've developed an application in java for ubuntu and want to open that application through its pid if it is already being running just like skype, skype is not create new instance if it is already running whethere clicks from the launcher(menu) insted of new instance it reopen same process.
102 Answers
If you have already typed a command and forgot to use the &, you can put a foreground job into the background by typing ^Z (Ctrl-Z) to suspend the job, followed by bg to put it into the background:
$ sleep 99
^Z
[1]+ Stopped sleep 99
$ bg
[1]+ sleep 99 &You can bring a background job into the foreground, so that the shell waits for it again, using fg:
$ jobs
[1]+ Running sleep 99
$ fg
sleep 99You can list the jobs of the current shell using the jobs command.
$ jobs
[1]+ Running sleep 99 If you want to run spacial job in foreground/background just use process id to move it to foreground/background. see this example:
$ sleep 99 # run first job
^Z
[1]+ Stopped sleep 99
$ bg
[1]+ sleep 99 &
$ sleep 1000 # run second job
^Z
[2]+ Stopped sleep 1000
$ jobs # view all jobs
[1]- Running sleep 99 &
[2]+ Stopped sleep 1000
$ bg %2 # move jobs number 2 to run in background
[2]+ sleep 1000 &
$ jobs # view all jobs
[1]- Running sleep 99 &
[2]+ Running sleep 1000 &Both of jobs are running in background.
$ fg %2 #switch to second job and run it in foreground sleep 1000 #sleep 1000 is now running in foregroundNote: You need to kill these jobs by using kill %processID.
example: kill %2 (kill second job with process ID #2)
According to @Peter.O's answer and question by @Omid in , if you get the PID of the program that you know which program it is, then with follow command you can switch to you desired program:
for example if you take PID of firefox with pidof command, like pidof firefox, you get the result something like 3547, then pass this PID to below command and switch to your program that you are used its PID:
wmctrl -ia $(wmctrl -lp | awk -vpid=$PID '$3==3547 {print $1; exit}') 7