Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Extracting process id

Help
Aravinda
2009-02-12
2013-05-02
  • Aravinda
    Aravinda
    2009-02-12

    Hi,

    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?

     
    • 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.

      Cheers,
      Vish.

       
    • 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.

      Thanks
      Aravinda