Erlang shell - controlling two processes - erlang

I have a question about erlang shell and erlang vm.
We have to write simple client-server application in Erlang, but only for local enviroment, so no sockets or anything.
I wanted to write something resembling a communicator server, people could register and send messages to other people. The thing is that if I open up erl and start my server/register it I can control only one process from the erlang shell, so there is no fun in that because I can't talk to anybody.
Is it possbile to open 2 erlang shells that are connected to the same instance of vm or compile the client program, start the server from erlang shell and then run the compiled clients in the same vm?

It is possible to open two shells connected to one VM (regular and
rem shell).
You can control many processes from one shell, just spawn
them.
What you probably really want is many erl VMs talking to each
other, even on one host. Just run them in distributed mode (e.g. with
-sname) and from now on you can communicate with anyone with the same cookie.
One of places to look at while learning erlang: http://learnyousomeerlang.com/distribunomicon#alone-in-the-dark

Related

Is there any way to isolate an app without using container under cygwin windows

I am using cygwin under windows server 2008 to have linux capability (to some degree) and ssh and be able to run apps without using a gui.
On another server that is ubuntu 18.04 I use containers to some how isolate my apps so that when I run an app and it spawns child processes and probabley modifies file descriptors etc (and so now I can not keep track of which processes are running now) I can stop my app and all the mess that it has done, with just stopping the container.
Containers made starting and stopping an app a clean and simple way.
Is there any way to have such thing on windows (without using docker on windows)? by saying this I mean the file and process isolation and not network or other stuff.
Is it possible to only isolate processes so that i can get rid of them with a single command?
Is there any tool for that? particularly for cygwin under windows?
I don't know about other languages but if you're using Python, it has a feature called Virtual Environment and developer can create and run applications in isolated environments. you can learn more about it here.
I myself come to the conclusion that using services and creating a service in windows would be the only way to manage an app without using a container.

pstack equivalent in erlang

When a Erlang system hangs I want to know what the system is doing during that time. For a c/c++ program, I can easily run the pstack, but I didn't find out a handy tool for this purpose in Erlang.
What is the pstack equivalent in Erlang?
Actually I want to check the running stack trace of the following process.
"/opt/couchbase/lib/erlang/erts-5.10.4.0.0.1/bin/beam.smp -P 327680 -K true -- -root /opt/couchbase/lib/erlang -progname erl --... "
and I started a new Erlang shell and start the webtool and check the appmon however I can't find the above application. What may cause this?
Thanks
Concerning pstack equivalent, have you read Erlang Profiling from official guide? It gives you lot of example on how to profile your application and find where your code stuck.
Another useful tools is observer it will show all working process, CPU usage, process stack and lot of more information.
If you don't see anything with these tools, you can try with Erlang debugger.
Now concerning couchbase, if your application is currently running, you can connect to it with Erlang shell and launch previous quoted commands and applications.
I don't know if you are using couchbase alone or with couchdb, but, if you want to use observer or other tools from command line, you can start couchdb with -i flag:
# -i use the interactive Erlang shell
couchdb -i
In case of your application run remotely without GUI, you can use etop, its a CLI alternative to observer. You can also dump etop output to file if you don't want to run it directly from your Erlang shell. IHMO, if you want more information concerning I/O or debug, use eprof, fprof and other profiling tools with dump file (see also eep profiling tool, easy to use).
Another alternative, if you are using SSH and want to see observer window, you can use X11Forwarding with ssh: ssh -X $yourserver or ssh -Y $yourserver and simply run observer:start(). in your Erlang shell.

getting process ID of a pub serve to then kill that thread/process

So when I run my Polymer Dart application, i use pub serve and the serve is created and served. It will stay running until until i break out of it. I was curious if there is a way to programmatically stop it.
One of the options I was looking at was looking at the running processes and then killing the pub serve process.
I was not sure though how i would get the process id to kill it, or unless there was another option.
Maybe someone has an even better approach to shutdown pub serve on the machine automatically, as a form of cleanup?
The issue I have noticed is that if i get the running proceesses, i only see "cmd" as a process so that isnt the best determining factor.
I was not sure if there was a way via pub on serve to get its process if, if it set a flag or global of sorts I could leverage
This is not a Dart or Pub question really, it's a Windows, MacOS, Linux etc. shell process control question.
The question is more suited to Stack Exchange Superuser https://superuser.com/ I believe. You could look over there for more detailed answer ... but ... assuming you are using the windows command prompt:
start /B starts a process in the background.
tasklist can be used to look up running process PIDs.
taskkill /PID kills a running process.
You can use help <command> or search for documentation.
I have not used these personally but it looks awkward as start /B does not give you the PID of the process it ran. Unix shells such as Bash have good facilities for running processes in the background. Windows Powershell may have better support also.

Start Erlang on startup.

I'm working on using erlang development server. Is there a way fro me to start the erlang vm and continue from the commandline or add a script to the startup files? To be clear I want to start erlang and keep it running outside of the command prompt.
You can use the -detached flag. See http://www.erlang.org/doc/man/erl.html for more information.
I usually use scripts, which rebar create-node do provide. There is such commands as: start, stop, ping and attach. Although you must use erlang releases in order to use this scripts (at list take a look at template, maybe it would be helpful)

Erlang - How to run more than one node on single windows vista machine?

i m graduate student and as my project i have to run Erlang Chat Application, but i am confused to run 2 nodes on my single machine having windows vista. can anybody help me please to run the application.
regards
anum
In one window run
c:\program files\erl5.7.1\bin\werl -sname x
and in another run
c:\program files\erl5.7.1\bin\werl -sname y
Check for the exact path to your Erlang system. This will give you two Erlangs running in separate windows on the same machine. As you are running them from the same user there should be no problems with authentication. Check the links in #Roberto's answer for more information and details of what is going on and how to get them to communicate with each other.
Here's an introduction to Distributed Erlang.
Here's an example where it's explained how to start two Erlang nodes on the same LAN.

Resources