blackode
Hi elixirians,
Here I am trying to monitor the process. Based on the official documentation I just tried with the follwing lines of code.
However the monitoring callback is not triggerd. Please help me to figure out this.
defmodule HelloServer do
use GenServer
## Client API
def start do
GenServer.start_link(__MODULE__,1, [])
end
def add pid,value do
GenServer.call(pid,{:add,value})
end
def get pid do
GenServer.call(pid,:get)
end
def reset pid do
GenServer.cast(pid, :reset)
end
def monitor pid do
GenServer.cast(pid, {:monitor, pid})
end
def stop pid do
Agent.stop(pid)
end
## Server API
def init(initial_value) do # initiating the state with the value 1 passed
{:ok,initial_value}
end
# add the value to the state and returns :ok
def handle_call({:add,value},_from,state) do
{:reply, :ok,state + value}
end
# returns the state to the caller
def handle_call(:get,_from,state) do
{:reply,state,state}
end
# just reset the state to value 1
def handle_cast(:reset,state) do
IO.puts "value has been reset "
{:noreply,1}
end
# monitor the given process id
def handle_cast({:monitor, pid},state) do
IO.puts "monitoring the process"
Process.monitor pid
{:noreply,1}
end
# This executes periodically
def handle_info(:work,state) do
IO.puts " This message prints every after 3 seconds"
schedule_work()
{:noreply,state}
end
# this is triggered when the agent stopped the process
def handle_info({:DOWN, ref, :process, _pid, _reason},state) do
IO.puts "Agent stopped the pid"
{:noreply, state}
end
#catch-all clause for the handle_info for handling unkown messages
def handle_info(_msg, state) do
IO.puts "unknown message"
{:noreply, state}
end
defp schedule_work() do
Process.send_after(self(), :work, 2 * 1000) # In 2 seconds
end
end
This is How I am using the file in iex
iex> {:ok, pid} = HelloServer.start
iex> HelloServer.monitor pid
iex> HelloServer.stop pid
# after calling this it should trigger the handle_info :DOWN ...
# but unfortunately not able to trigger that..
# am I missing something here ?
Thanks in advance. ![]()
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
yurko
You’d have to monitor the process from another process, there is no use in dead process’ inbox (that would receive a down message). Something like that (from the iex’ process):
blackode
This means I have written the callback trigger in the dead process which is no way of triggering if I am not wrong. Thanks for making this clear with out any confusion.

I missed the logic here.
Thanks for the help