Find process ID of a background process

时间:2016-10-20 12:40:25

标签: linux

I am execute a infinite while loop from command line that would execute a rest call with the use of CURL . I'm redirecting the rest o/p to a file . I have appended an "&" at the end of the command so that it goes into background. Unfortunately, the terminal was exited . But I see the process is still writing the o/p to the file continuously . However I don't see any background jobs running with the command job. Even I used ps/lsof/fuser to find the process ID so that I can manually kill it. But none of the commands returned me the process ID. I even tried changing the file to read only mode, but still I see the file continuously growing.

At last I found chattr command that would restrict the file from being written.

But in this case where would I find the process ID that is responsible .

touch /var/log/test_mon_vm.log;while true; echo "start....." >>/var/log/test_mon_vm.log;echo $(date) >> /var/log/test_mon_vm.log; do /usr/bin/curl -I --user rhqadmin:rhqadmin http://localhost:7080/rest/plugins?name=Samba 2>/dev/null | head -n 1 >> /var/log/test_mon_vm.log; echo "end....." >> /var/log/test_mon_vm.log;echo >>/var/log/test_mon_vm.log;echo >>/var/log/test_mon_vm.log;sleep 1;done &

3 个答案:

答案 0 :(得分:0)

You can find the ID with

ps -fea|grep [your USER]

then search the script list, there's gonna be, if you use an script replace your user with the script name

答案 1 :(得分:0)

You can use fg

Background Processes in linux

once the background process is in the foreground you can kill it using ctrl+c

I hope this helps! Have a nice day!

答案 2 :(得分:0)

You can try

ps aux | grep "command-you-ran"

e.g.

ps aux | grep "curl"