Why write a c# program instead of a simple shell script?
You use Process.Start() to run a utility.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi Team,
I have a C# .NET Core 3.1 console application which is running on terminal window in RedHat Linux.
It is a long running application. it runs 24/7. Currently application is blocking the terminal window when it is running.
Now i got new change request which i need to implement
Change Request
The application has to run on background by following way in Linux terminal window,
Linux terminal window should not be blocked.
The commands are like below,
START appName
STOP appName
STATUS appname
Could you please help me on this?
Regards,
Prabs
Why write a c# program instead of a simple shell script?
You use Process.Start() to run a utility.
How to handle the below commands in C#.Net core console application?
! start foo in background
foo > foo.log &
! get status
tail foo.log
! stop foo
pkill foo
linux does not have the equivalent of nt services. you have cron jobs, or daemons. cron redirects stdin, stdout and stderr before it starts the job.
linux does not have a create process like nt. instead it has a fork() which creates an exact copy of the code running in memory. the return value of fork() tells the caller if it the parent or the child after the fork().
to start a process, your code does a fork(), then the child process reassigns files handles as desired and loads a new image. the new image inherits the open file handles.
to stop a program you send it a signal(9). the kill command can do this. typically ^c is converted to signal(9).
while you can code your program to auto detach, usually shell programs are used to start a process, they usually have a command to start a job in the background (typically & at end). they also have a command to list jobs, and attach to a job and kill a job
bash>my program&
bash>jobs
see the ^c, ^z, fg, bg, jobs commands for the shell of your choice.
for status, the program typically writes to a log file, and you use the tail command to get the current status.
so if your .net command tool is name foo, then
! start foo in background
foo > foo.log &! get status
tail foo.log! stop foo
pkill foo