LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   [SOLVED] Put a process in foreground with his PID (https://www.linuxquestions.org/questions/linux-newbie-8/%5Bsolved%5D-put-a-process-in-foreground-with-his-pid-751867/)

gagou7 09-01-2009 01:56 PM

[SOLVED] Put a process in foreground with his PID
 
Hi,

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 !

fordeck 09-01-2009 04:33 PM

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

Regards,

Fordeck

gagou7 09-02-2009 03:17 AM

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.

[EDIT]

I found a solution.
In your php script, if you do this:
Code:

system('screen -dmS rTorrent rtorrent');
you will have an error that say "Must be connected to a terminal".

The correct command is:
Code:

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:
Code:

:~$ sudo -u www-data screen -ls
or this to rattach the "rTorrent" screen:
Code:

:~$ sudo -u www-data screen -r rTorrent
Note that "www-data" is the user declared in apache.conf.

Maybe you will have this error:
Code:

:~$ sudo -u www-data screen -r rTorrent
Cannot open your terminal '/dev/pts/0' - please check.

Just do this to solve the problem:
Code:

:~$ chmod a+rw /dev/pts/0
Not need the "&" at the end or "nohup", all working fine !
[/EDIT]


All times are GMT -5. The time now is 11:03 PM.