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

    Join Date
    Mar 2013
    Rep Power

    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

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

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

    sleep 6000 &
    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 10: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