Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-01-2009, 02:56 PM   #1
LQ Newbie
Registered: Sep 2009
Distribution: Ubuntu 9.04 / Debian 5.0 / Backtrack 3
Posts: 27

Rep: Reputation: 0
[SOLVED] Put a process in foreground with his PID


I'm sorry for my poor english but I'm French. I try to run a command trough a php page. There's my command:

system('bash -c \"screen -dm rtorrent\"');

I think the command is working fine because when I log on by ssh on my Debian server I can see the screen process with "ps -A" command. But if I type "screen -ls" in a shell, I don't see anything...

The command "jobs" don't return anything too, it's why I can't use "fg"...

Maybe that's "screen" the problem. But if I try with "nohup...&" I don't know how to retrieve my process in foreground...

Thank's for any help !

Last edited by gagou7; 09-05-2009 at 10:35 AM.
Old 09-01-2009, 05:33 PM   #2
Registered: Oct 2006
Location: Utah
Posts: 520

Rep: Reputation: 61
What user does the php script run under? If you are not logged in as that user then I believe you would not be able to see his screen sessions with the:

screen -ls

But you could still see the screen process running when you issue the ps -A command. You might sudo to your php user and then try:

screen -ls


Old 09-02-2009, 04:17 AM   #3
LQ Newbie
Registered: Sep 2009
Distribution: Ubuntu 9.04 / Debian 5.0 / Backtrack 3
Posts: 27

Original Poster
Rep: Reputation: 0
I have 3 users. The user "www-data" in the "www-data" group used by Apache. The php script run under this user.
Normally, I log on by ssh on my server with the user "gagou" in the group "www-data" and I can't see the screen started by "www-data".
I try with another user "local" in the group "www-data" and I can't see the screen started by "www-data" too.

But if I run a screen with the user "gagou", then log off and log on with the user "local", I can see and attach the screen started by "gagou".
All 3 users are in the same group. I don't know where's the problem.

I would try with sudo and post the result.

Thank's a lot.


I found a solution.
In your php script, if you do this:
system('screen -dmS rTorrent rtorrent');
you will have an error that say "Must be connected to a terminal".

The correct command is:
system('/bin/bash -c "/usr/bin/screen -dmS rTorrent /usr/bin/rtorrent"');
rtorrent start in a screen !

If you want to retrieve the screen when you connect for example by ssh, you must do this to see all screen started by the php script:
:~$ sudo -u www-data screen -ls
or this to rattach the "rTorrent" screen:
:~$ sudo -u www-data screen -r rTorrent
Note that "www-data" is the user declared in apache.conf.

Maybe you will have this error:
:~$ sudo -u www-data screen -r rTorrent
Cannot open your terminal '/dev/pts/0' - please check.
Just do this to solve the problem:
:~$ chmod a+rw /dev/pts/0
Not need the "&" at the end or "nohup", all working fine !

Last edited by gagou7; 09-05-2009 at 10:39 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i bring the backgroud process to foreground ZAMO Linux - Enterprise 10 03-05-2012 10:35 AM
Scripting: How to put wget in foreground? klss Linux - Software 7 01-13-2009 05:53 PM
How to get the PID of the process giving kill signal to a process? hariprd Programming 2 11-27-2008 04:10 AM
background process popping up in foreground noir911 Linux - General 1 12-15-2007 12:53 AM
How to know the foreground process group ID of another console ?? sreeramabsc Linux - General 0 01-30-2006 02:26 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:49 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration