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

    Join Date
    Jan 2008
    Posts
    209
    Rep Power
    9

    Awk xargs kill, illegal pid what's wrong?


    I have the following code. On cygwin I get the following erros:

    $ torak
    kill: illegal pid: User
    kill: illegal pid: cons0
    kill: illegal pid: 05:12:32
    kill: illegal pid: /cygdrive/s/_flash/Motion-Twin/neko/neko

    alias torak="ps -ef | awk '/cygdrive\/s\/_flash\/Motion\-Twin\/neko\/neko/{print $2}' | xargs kill"

    What is the problem?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,436
    Rep Power
    1688
    What happens if you run the command without the final pipe into xargs by hand?
    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
  4. #3
  5. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,424
    Rep Power
    4539
    Maybe it's a line termination problem, you could try xargs -0

    Just a guess.
    ======
    Doug G
    ======
    The man who doesn't read good books has no advantage over the man who can't read them.
    --Mark Twain
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2008
    Posts
    209
    Rep Power
    9
    @Doug It may be but i dont replacing it with null characters would be relevant in this case.

    The output of the awk is:

    $ ps -ef | awk '/cygdrive\/s\/_flash\/Motion\-Twin\/neko\/neko/{print $2}'
    7184
    Executing echo "6712" | xargs kill works

    The output of:

    echo "hello world" | awk '/hello/{print $1}' is

    hello
    Last edited by imagenesis; May 6th, 2012 at 05:56 PM.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,436
    Rep Power
    1688
    I may have it. It's down to it being an alias - when you define it the variable $2 does not contain a value, so the alias value is invalid. Quote the $ (\$) to prevent it being evaluated at creation time and try that.
    <edit>
    Yes, that worked for me Use alias -p to see what is defined
    </edit>
    Last edited by SimonJM; May 8th, 2012 at 05:52 AM. Reason: Tetsed it!
    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