#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Sleep command in background


    I am trying to

    1) start the command "sleep 6000" in the background
    2) use ps to determine its status
    3) redirect the ps command to a file
    4) kill the sleep process
    5) run ps to verify the process is dead.

    I am not asking for the answer, but just someone more versed in UNIX to see if what I am doing is correct. Here are my steps thus far:

    1. sleep 6000 &
    2 + 3. ps > /var/home/stud3/myname/myfile
    4. kill 61040 PID (61040 was the PID and I read I had to type PID after the numerical value)
    5. ps

    Thanks!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,442
    Rep Power
    1688
    Not sure what the + 3. bit is, but the way I'd do it is:

    Code:
    sleep 6000 &
    pid=$!
    ps -fp $pid > /var/home/stud3/myname/myfile
    kill $pid
    ps -fp $pid
    Penny dropped on the + 3. .. d'oh! That's what trying to think at 3:30 in the morning does for you
    Last edited by SimonJM; March 9th, 2013 at 09:34 PM. Reason: Comprehension despite being over-tired! ^_^
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo