React native terminal, how to get the process id of new terminal window launched by `react-native start`?

Viewed 109

When I run a command like react-native run-ios or react-native start, it launches a new terminal window with the react native compiling process running/watching inside of the new terminal window.

How can I watch for this new process to start? Or find it among running terminal processes? Find the pid, etc.

My task is specific and obscure, but this is more or less exactly what I need to do. Can anyone help?

1 Answers

Checking which PID is used for the port of your react native application should suffice. The standard port for the react-native-cli when running react-native run-ios or react-native start is 8081. For expo it is 19000.

For specifying a custom port (e.g. 9988) use

react-native start --port 9988

When your react native application is running, then you can check the corresponding PID in usage for that port (sudo might be needed at the beginning of the command)

lsof -i -P | grep LISTEN | grep 8081

node      38273 [USER]   31u  IPv6 0x2207bcb724ddd40d      0t0  TCP *:8081 (LISTEN)

In this example, the corresponding PID is 38273

Related