Extracting process id

  • Aravinda

    Aravinda - 2009-02-12


    I am trying to extract PID of running process and the following code gives error.

    catch {spawn ps aux | grep sim_gold | grep -v grep | awk '{print $2'} } pid

    puts $pid

    and if I use the variable pid to print or anything it throws the following error.

    pid can't read "2": no such variable

    Please help me what is wrong here?

    • venkata kopparapu

      I am also new to expect and trying to get hands on it.But if your main intention is to get a process id of the current spawned process you can use exp_pid and store it in a variable.

      so if you spawn a program process_xyz this is how you can use

      spawn process_xyz
      set process_id [exp_pid]

      If you are in some other spawned process context and stored the spawned id required in a variable spawn_req_id this is how you can get

      set process_id [exp_pid -i $spawn_req_id]

      Note : process_id and spawn_req_id are variables . exp_pid is actually a command . You can get more info on it by searching.


    • Aravinda

      Aravinda - 2009-02-13

      Thanks it helped me a lot.

      Actually when I searched I got some examples and I combined both of them it started working.

      spawn ./my_prog -e ffffff -i image.hex -p $port
      set pid [ exp_pid]
      puts "Spawn id = $spawn_id PID is $pid"

      It worked.



Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks