File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
77warrant a full blog post. These are mostly things I learn by pairing with
88smart people at [ Hashrocket] ( http://hashrocket.com/ ) .
99
10- _ 511 TILs and counting..._
10+ _ 512 TILs and counting..._
1111
1212---
1313
@@ -90,6 +90,7 @@ _511 TILs and counting..._
9090- [ Compute md5 Digest Of A String] ( elixir/compute-md5-digest-of-a-string.md )
9191- [ Counting Records With Ecto] ( elixir/counting-records-with-ecto.md )
9292- [ Create A Date With The Date Sigil] ( elixir/create-a-date-with-the-date-sigil.md )
93+ - [ Creating A PID] ( elixir/creating-a-pid.md )
9394- [ Creating Indexes With Ecto] ( elixir/creating-indexes-with-ecto.md )
9495- [ Determine The Latest Release Of A Hex Package] ( elixir/determine-the-latest-release-of-a-hex-package.md )
9596- [ Do You Have The Time?] ( elixir/do-you-have-the-time.md )
Original file line number Diff line number Diff line change 1+ # Creating A PID
2+
3+ Often times, when invoking a function that spawns a process, the PID of the
4+ spawned process is returned and we bind to it. That PID is a reference to
5+ some BEAM process in our system.
6+
7+ We can create our own references using the ` pid/3 ` function.
8+
9+ Let's assume we have the following processes, among others, in our system at
10+ the moment.
11+
12+ ``` elixir
13+ > Process .list |> Enum .reverse |> Enum .take (3 )
14+ [# PID<0.284.0>, #PID<0.283.0>, #PID<0.282.0>]
15+ ```
16+
17+ We can create a reference to any of them using the three number parts that
18+ they are made up of.
19+
20+ ``` elixir
21+ > pid (0 , 284 , 0 )
22+ # PID<0.284.0>
23+ ```
24+
25+ See, it's alive.
26+
27+ ``` elixir
28+ > pid (0 , 284 , 0 ) |> Process .alive?
29+ true
30+ ```
31+
32+ What if we make up a PID that doesn't actually reference any process?
33+
34+ ``` elixir
35+ > pid (0 , 333 , 0 ) |> Process .alive?
36+ false
37+ ```
38+
39+ Note: there is also a ` pid/1 ` version of the function. See ` h pid ` for more
40+ details.
You can’t perform that action at this time.
0 commit comments